[英]How to rebase a branch in git one revision closer to head of other branch?
我目前正在努力将一个项目的 2 个长期分歧的分支feature/A
和feature/B
重新组合在一起。 在此期间,他们积累了许多相互矛盾的变化。 在另一个之上重新建立一个基础是不可行的,因为发生了很多变化。
因此,我迭代地重新定位feature/B
一个更接近feature/A
头部的提交。 我正在使用一个名为feature/rebase-target
的分支,该分支跟踪我当前正在基于feature/B
的功能/ feature/A
上的提交。 我的工作流程基本上是:
git checkout feature/rebase-target && git rebase <sha-1 of the next commit towards feature/A head>
git checkout feature/B && git rebase feature/rebase-target
feature/A
的日志手动找到下一个 sha-1 如何根据feature/rebase-target
的当前位置自动搜索更接近feature/A
头部的一次提交的 sha-1?
你可以这样做:
next_target=$(git rev-list feature/rebase-target..feature/A | tail -n1) &&
git branch -f feature/rebase-target "$next_target"
这假设历史是线性的。 如果您在通往feature/A
的分支中有合并,请添加--first-parent
。
请注意, rev-list --reverse -1
不起作用,因为这将首先将正常列表限制为一次提交,然后反转输出(如果只列出一个则没有区别)。
进一步注意,在您的第 1 步中,您不必在rebase
之后checkout
(如果我正确理解情况,这是一个快进); 你可以只使用git branch -f
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.