跳到正文
cccskills
免费在 GitHub 公开

rebase-onto-main

Rebase a branch onto main, handling squash-merged parent branches cleanly

中文简介正在准备中。当前显示原文说明。

mengchaoheng/DuctedFanUAV-Autopilot星标 19(GitHub 19 + cccskills 0)

实测评分 未实测

查看安装方法

包含的文件(1)

  • SKILL.md2.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Rebase Branch onto Main

Rebase the current (or specified) branch onto main, correctly handling the case where the branch was built on top of another branch that has since been squash-merged into main.

Background

When a parent branch is squash-merged, its individual commits become a single new commit on main with a different hash. A normal git rebase main will try to replay the parent's original commits, causing messy conflicts. The fix is to cherry-pick only the commits unique to this branch onto a fresh branch from main.

Steps

  1. Identify the branch. Use $ARGUMENTS if provided, otherwise use the current branch.

  2. Fetch and update main:

    git fetch origin main:main
    
  3. Find the merge base between the branch and main:

    git merge-base <branch> main
    
  4. List all commits on the branch since the merge base:

    git log --oneline <merge-base>..<branch>
    
  5. Identify which commits are unique to this branch vs. inherited from a parent branch. Look for:

    • Squash-merged commits on main that correspond to a group of commits at the bottom of the branch's history (check PR titles, commit message keywords).
    • The boundary commit: the first commit that belongs to this branch's work, not the parent's.
    • If ALL commits are unique (no parent branch), just do a normal git rebase main and skip the rest.
  6. Create a fresh branch from main:

    git checkout -b <branch>-rebase main
    
  7. Cherry-pick only the unique commits (oldest first):

    git cherry-pick <first-unique-commit>^..<branch>
    

    The A^..B range means "from the parent of A through B inclusive."

  8. Handle conflicts if any arise during cherry-pick. Resolve and git cherry-pick --continue.

  9. Replace the old branch:

    git branch -m <branch> <branch>-old
    git branch -m <branch>-rebase <branch>
    
  10. Verify the result:

    git log --oneline main..<branch>
    

    Confirm only the expected commits are present.

  11. Ask the user before force-pushing. When approved:

    git push origin <branch> --force-with-lease
    
  12. Clean up the old branch:

    git branch -D <branch>-old
    

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

commit

免费

Create a conventional commit for PX4 changes

中文简介正在准备中。当前显示原文说明。

mengchaoheng/DuctedFanUAV-Autopilot192026年10月30日 更新

pr

免费

Create a pull request with conventional commit title and description

中文简介正在准备中。当前显示原文说明。

mengchaoheng/DuctedFanUAV-Autopilot192026年10月30日 更新

review-pr

免费

Review a pull request with structured, domain-aware feedback

中文简介正在准备中。当前显示原文说明。

mengchaoheng/DuctedFanUAV-Autopilot192026年10月30日 更新

查看 mengchaoheng 的全部技能

报告此技能的问题