git-rebase-workflow

Git Rebase 分支同步流程,用于将当前功能分支 rebase 到最新的目标分支(如 master/main),保持提交历史整洁。适用于功能分支落后于目标分支时,需要同步最新代码的场景。

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "git-rebase-workflow" with this command: npx skills add nangongwentian-fe/agent-skills/nangongwentian-fe-agent-skills-git-rebase-workflow

Git Rebase 工作流

将当前功能分支 rebase 到最新的目标分支(通常是 master/main),保持线性提交历史。

使用场景

  • 功能分支落后于 master,需要同步最新代码
  • 提交 MR/PR 前保持提交历史整洁
  • 避免使用 git merge 产生的合并提交

前置检查

  1. 确认当前分支状态:

    git branch -v
    git status
    
  2. 确认工作区干净(无未提交的更改)

Rebase 流程

1. 获取最新代码

git fetch origin <目标分支>

2. 执行 Rebase

git rebase origin/<目标分支>

3. 解决冲突(如有)

如果出现冲突,按以下步骤处理:

  1. 查看冲突文件:

    git status
    
  2. 查看冲突详情:

    grep -n "<<<<<<< HEAD\|=======\|>>>>>>>" <冲突文件>
    
  3. 解决冲突策略:

    • 保留目标分支版本(ours):

      git checkout --ours <文件路径>
      
    • 保留当前分支版本(theirs):

      git checkout --theirs <文件路径>
      
    • 手动编辑: 直接修改冲突文件,删除冲突标记

  4. 标记冲突已解决:

    git add <文件路径>
    
  5. 继续 rebase:

    git rebase --continue
    
  6. 如需中止 rebase:

    git rebase --abort
    

4. 推送更新

git push origin <当前分支> --force-with-lease

注意:必须使用 --force-with-lease 安全地强制推送

常见问题

冲突解决原则

  • 版本号冲突: 通常保留较新的版本
  • API 变更: 根据具体情况分析,询问用户意图
  • 配置变更: 评估变更影响,选择合适的版本

安全建议

  1. rebase 前确保有备份或已推送的分支
  2. 不要对公共分支(如 master)执行 rebase
  3. 使用 --force-with-lease 而非 --force 推送
  4. 如有不确定,先询问用户选择

完整示例

# 1. 检查状态
git branch -v
git status

# 2. 获取最新代码
git fetch origin master

# 3. 执行 rebase
git rebase origin/master

# 4. 解决冲突(如需要)
# - 查看冲突: git status
# - 保留 ours/theirs 或手动编辑
# - git add <文件>
# - git rebase --continue

# 5. 推送
git push origin feature-branch --force-with-lease

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

persistent-memory

No summary provided by upstream source.

Repository SourceNeeds Review
Research

exa-unified-research

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

code-review-uncommitted

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

vercel-composition-patterns

React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.

Repository Source
85.9K23Kvercel