rebase

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Rebase

Rebase

Rebase the current branch onto the latest
origin/main
.
将当前分支Rebase到最新的
origin/main
分支。

Usage

使用场景

When asked to rebase:
  1. Check current state:
    bash
    git status
    git branch --show-current
    • If on
      main
      , warn the user and stop — rebasing main onto itself is a no-op
    • If there are uncommitted changes, warn the user and stop — do NOT stash automatically
  2. Fetch latest:
    bash
    git fetch origin
  3. Rebase onto main:
    bash
    git rebase origin/main
  4. Handle conflicts:
    • If the rebase succeeds cleanly, proceed to step 5
    • If there are conflicts:
      • List the conflicting files
      • Ask the user how they want to proceed: resolve manually, or abort
      • Do NOT force-continue or blindly resolve conflicts
      • To abort:
        git rebase --abort
  5. Confirm — Print a summary:
    text
    Rebased feat/123-add-watch-mode onto origin/main
    • Do NOT push automatically
    • If the user explicitly asks to push, use
      git push --force-with-lease
    • NEVER use
      --force
      — always
      --force-with-lease
      for safety
当需要执行Rebase操作时:
  1. 检查当前状态:
    bash
    git status
    git branch --show-current
    • 如果当前在
      main
      分支,警告用户并停止——将main分支Rebase到自身无意义
    • 如果存在未提交的变更,警告用户并停止——不要自动执行stash
  2. 拉取最新代码:
    bash
    git fetch origin
  3. Rebase到main分支:
    bash
    git rebase origin/main
  4. 处理冲突:
    • 如果Rebase顺利完成,进入步骤5
    • 如果存在冲突:
      • 列出冲突文件
      • 询问用户如何处理:手动解决,还是终止Rebase
      • 不要强制继续或盲目解决冲突
      • 终止命令:
        git rebase --abort
  5. 确认操作 —— 打印总结信息:
    text
    Rebased feat/123-add-watch-mode onto origin/main
    • 不要自动推送
    • 如果用户明确要求推送,使用
      git push --force-with-lease
    • 绝对不要使用
      --force
      —— 为了安全,始终使用
      --force-with-lease

Important

注意事项

  • NEVER rebase
    main
    itself
  • NEVER use
    git push --force
    — always
    --force-with-lease
  • NEVER stash or discard uncommitted changes — warn and stop
  • NEVER use
    --no-edit
    or
    -i
    flags with rebase
  • If conflicts occur, always involve the user — never auto-resolve
  • 绝对不要Rebase
    main
    分支本身
  • 绝对不要使用
    git push --force
    —— 始终使用
    --force-with-lease
  • 绝对不要stash或丢弃未提交的变更 —— 警告用户并停止
  • 绝对不要在Rebase时使用
    --no-edit
    -i
    参数
  • 如果发生冲突,务必让用户参与处理——绝不自动解决冲突