rebase-assistant

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rebase assistant

Rebase助手

Goal

目标

Rebase the current branch onto a target branch safely, with built-in conflict resolution guidance.
安全地将当前分支变基到目标分支,内置冲突解决指南。

Inputs to confirm (ask if missing)

待确认的输入项(缺失时请询问用户)

  • Target branch (explicit branch name or "default branch").
  • Preferred conflict bias when ambiguous: keep ours, keep theirs, or manual merge.
  • Protected paths or file types to avoid touching.
  • 目标分支(明确的分支名称或「默认分支」)。
  • 歧义场景下的优先冲突处理倾向:保留我方改动、保留对方改动,或手动合并。
  • 需要避免改动的受保护路径或文件类型。

Workflow

工作流程

  1. Identify the target branch
    • If user says "default branch": discover via
      git remote show origin
      (read "HEAD branch").
    • If ambiguous or no remote: ask the user which branch to use.
  2. Preflight checks
    • git status -sb
      (must be clean before rebase).
    • git fetch --prune
      to sync remotes.
    • Optional safety branch (ask before creating):
      git branch backup/<current-branch>
      .
  3. Start the rebase
    • git rebase <target-branch>
  4. If conflicts occur, resolve (repeat per file)
    • Inspect conflict list:
      • git status -sb
      • git diff --name-only --diff-filter=U
    • Classify and inspect:
      • Content conflicts: open file, resolve markers.
      • Delete/modify or rename conflicts: decide keep vs delete explicitly.
      • Binary conflicts: choose ours/theirs only.
    • Show base/ours/theirs when useful:
      • git show :1:<path>
      • git show :2:<path>
      • git show :3:<path>
    • File-level choice when safe:
      • git checkout --ours <path>
      • git checkout --theirs <path>
    • Stage resolved files:
      git add <path>
    • Continue:
      git rebase --continue
  5. Finish and verify
    • Ensure no conflicts:
      git status -sb
    • Suggest a fast test/build if available.
  1. 确定目标分支
    • 如果用户提到「默认分支」:通过
      git remote show origin
      查询(读取「HEAD branch」字段)。
    • 如果存在歧义或没有远程仓库:询问用户需要使用的分支。
  2. 预检
    • 执行
      git status -sb
      (变基前必须保证工作区干净)。
    • 执行
      git fetch --prune
      同步远程仓库信息。
    • 可选的安全备份分支(创建前需询问用户):
      git branch backup/<current-branch>
  3. 启动变基
    • git rebase <target-branch>
  4. 出现冲突时进行解决(每个文件重复以下步骤)
    • 查看冲突列表:
      • git status -sb
      • git diff --name-only --diff-filter=U
    • 分类检查冲突:
      • 内容冲突:打开文件,解决冲突标记。
      • 删除/修改或重命名冲突:明确决定保留还是删除。
      • 二进制文件冲突:仅可选择保留我方/对方版本。
    • 必要时展示基础版本/我方版本/对方版本:
      • git show :1:<path>
      • git show :2:<path>
      • git show :3:<path>
    • 安全场景下可进行文件级选择:
      • git checkout --ours <path>
      • git checkout --theirs <path>
    • 暂存已解决的文件:
      git add <path>
    • 继续变基:
      git rebase --continue
  5. 完成并验证
    • 执行
      git status -sb
      确保无冲突。
    • 若有可用的测试/构建流程,建议快速运行验证。

Safety rules

安全规则

  • Never run
    git reset --hard
    ,
    git clean -fd
    , or
    git rebase --abort
    unless the user explicitly requests it.
  • Always show candidate commands before applying destructive changes.
  • 除非用户明确要求,否则永远不要执行
    git reset --hard
    git clean -fd
    git rebase --abort
    命令。
  • 执行破坏性改动前必须先展示待执行的候选命令。

Deliverables

交付物

  • The exact rebase command used and target branch.
  • Conflict list grouped by type with per-file resolution guidance.
  • Completion command and a short verification suggestion.
  • 实际使用的变基命令和目标分支。
  • 按类型分组的冲突列表,以及每个文件的解决指南。
  • 完成命令和简短的验证建议。