Git rebase,跳过merge-commits [英] Git rebase, skip merge-commits
问题描述
以
开头 破解--- F1 ---- M1 ---- F2(功能)
/ /
C1 ----- C2 ---- C3(主)
我想结束
hack --- F1 ---- M1 ---- F2(功能)
/
C1 ----- C2 ---- C3 --- F1'--- F2'(master)
到目前为止,我拥有的最好的是
git checkout feature
git checkout -b temp
git rebase -i --onto master hack temp
*大缺点:从提交列表中手动删除合并的C2和C3 *
git checkout master
git merge temp
git branch -d temp
我希望有人能回答即使这是一个可疑的工作流程。
如果您的回购的状态为
破解--- F1 ---- M1 ---- F2 [功能]
/ /
C1 ----- C2 ---- C3 [master]
并且您想到达
hack --- F1 ---- M1 ---- F2 [特点]
/ /
C1 ----- C2 ---- C3 ---- F1'---- F2'[HEAD = master]
您应该使用 git cherry-pick
,而不是 git rebase -i
(在这里,不需要与交互式rebase混合使用):
git checkout master
git cherry-pick< commit -ID-的-F1>提交-ID-的-F2>其中p
一般情况
如果我错了,但我明白你的意思是通过 general case em> 作为
cherry-pick,位于
master
,hack
(独占)与特性的小费之间的所有非合并提交
(含)。
在下面的例子中,我假设你确实是这个意思。
正如你在评论中正确地指出的那样,上面提到的方法并不像手动挑选提升的提交数量那样优雅地伸缩:
hack --- F1 --- F2 --- .... --- F68 - M1 --- F67 --- ... ..-- F99 [特征]
/ /
C1 ------------- C2 --------------- C3 [master]
但是,您可以获得 git使用
git rev-list - rev-list
自动生成感兴趣修订列表。 -no-merges --first-parent< commit-ID-of-hack> .. feature
编辑:您还需要 - first-parent
标志来避免收集提交,如 C1
和 C2
和 - reverse
标志,以便提交按所需顺序进行挑选。
您可以将该命令的输出传递给 git cherry-pick
:
git checkout master
git cherry-pick`git rev-list --no-merges --first-parent< commit-ID-of-hack> .. feature`
会产生收益
hack --- F1 --- F2 --- .... --- F68 - M1 --- F67 --- ... ..-- F99【特征】
/ /
C1 ------------- C2 --------------- C3 --- F1'--- F2'---。 ..--- F99'[HEAD = master]
Starting with
hack---F1----M1----F2 (feature)
/ /
C1-----C2----C3 (master)
I would like to end up with
hack---F1----M1----F2 (feature)
/ /
C1-----C2----C3---F1'---F2' (master)
So far the best I have is
git checkout feature
git checkout -b temp
git rebase -i --onto master hack temp
* Big drawback: manually remove the merged-in C2 and C3 from list of commits *
git checkout master
git merge temp
git branch -d temp
I hope someone can answer even though this is a dubious workflow.
Simple case
If the state of your repo is
hack---F1----M1----F2 [feature]
/ /
C1-----C2----C3 [master]
and you want to arrive at
hack---F1----M1----F2 [feature]
/ /
C1-----C2----C3----F1'----F2' [HEAD=master]
you should use git cherry-pick
, not git rebase -i
(no need to juggle with interactive rebase, here):
git checkout master
git cherry-pick <commit-ID-of-F1> <commit-ID-of-F2>
General case
Correct me if I'm wrong, but I understand what you mean by general case as
cherry-pick, on top of
master
, all the non-merge commits betweenhack
(exclusive) and the tip offeature
(inclusive).
In the following, I'm assuming that is indeed what you mean.
As you've rightfully noted in your comment, the approach outlined above doesn't scale very gracefully as the number of commits to manually cherry-pick increases:
hack---F1---F2--- .... --- F68--M1---F67---...---F99 [feature]
/ /
C1-------------C2---------------C3 [master]
However, you can get git rev-list
to automatically generate the list of revisions of interest, using
git rev-list --no-merges --first-parent <commit-ID-of-hack>..feature
Edit: you also need the --first-parent
flag to avoid collecting commits such as C1
and C2
, and --reverse
flag, so that commits get cherry-picked in the desired order.
You can pass the output of that command to git cherry-pick
:
git checkout master
git cherry-pick `git rev-list --no-merges --first-parent <commit-ID-of-hack>..feature`
which would yield
hack---F1---F2--- .... --- F68--M1---F67---...---F99 [feature]
/ /
C1-------------C2---------------C3---F1'---F2'---...---F99' [HEAD=master]
这篇关于Git rebase,跳过merge-commits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!