--preserve-合并当前分支中所有提交的交互式rebase [英] interactive rebase with --preserve-merges of all commits in the current branch

查看:104
本文介绍了--preserve-合并当前分支中所有提交的交互式rebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎已经有一些类似的问题,但这些都不是我想要的.

There seem to be some similar questions already, but none of them are exactly what I want.

假设我有这样的提交历史

Let's say I have commit history like this

* xxxxxxxH (HEAD -> B) Latest commit
* (more commits)
* xxxxxxxG (B) More commits
*   xxxxxxxF Merge branch 'master' into B
|\  
| * xxxxxxxE (master) Another commit on master
| * (more commits here)
| * xxxxxxxD Commit on master
* | xxxxxxxC Another commit 
* | (more commits here)
* | xxxxxxxB First commit on branch A
|/  
* xxxxxxxA (master) some commit

现在,我想重写分支A的历史记录,可能会合并或编辑某些提交,但是我还想更改分支A上的第一次提交,并且我还想保留合并,以便保留master的合并进入A.

Now I want to rewrite the history of branch A, potentially merging or editing some commits, but I also want to change the first commit on branch A, and also I want to preserve merges, so that I keep the merge of master into A.

我首先直观地尝试了git rebase -i -p xxxxxxxB,但是很明显,这不包括xxxxxxxB提交本身.因此,另一尝试是git rebase -i -p xxxxxxxB^确实包含了该提交,但现在实际上并没有保留合并.

I first intuitively tried git rebase -i -p xxxxxxxB, but obviously that didn't include the xxxxxxxB commit itself. So another attempt was git rebase -i -p xxxxxxxB^ which did include that commit, but now it didn't actually to preserve merges.

另一个很有希望的选择是--root,但这是从整个存储库中的第一次提交开始的,这也不是我想要的.

Another option that looked promising was --root, but this one starts from the very first commit in the whole repository which is also not what I want.

有什么办法可以做我想做的事吗?

Is there any way to do what I want?

推荐答案

在超出我认为合理的时间之后,我才能够在irc上获得解决方案:

After longer than I considered reasonable, I was able to get a solution on irc:

git rebase -i -m -r firstCommitInBranch^完全满足我的需求.

从git文档中:

   -r, --rebase-merges[=(rebase-cousins|no-rebase-cousins)]
       By default, a rebase will simply drop merge commits from the todo list, and put
       the rebased commits into a single, linear branch. With --rebase-merges, the
       rebase will instead try to preserve the branching structure within the commits
       that are to be rebased, by recreating the merge commits. Any resolved merge
       conflicts or manual amendments in these merge commits will have to be
       resolved/re-applied manually.
       (...)
       The --rebase-merges mode is similar in spirit to --preserve-merges, but in
       contrast to that option works well in interactive rebases: commits can be
       reordered, inserted and dropped at will.

   -m, --merge
       Use merging strategies to rebase. When the recursive (default) merge strategy is
       used, this allows rebase to be aware of renames on the upstream side.

我还错过了文档中说不要与-i一起使用-p的部分:

I also missed the part of documentation that said to not use -p together with -i:

   -p, --preserve-merges
       Recreate merge commits instead of flattening the history by replaying commits a
       merge commit introduces. Merge conflict resolutions or manual amendments to merge
       commits are not preserved.

       This uses the --interactive machinery internally, but combining it with the
       --interactive option explicitly is generally not a good idea unless you know what
       you are doing (see BUGS below).

这篇关于--preserve-合并当前分支中所有提交的交互式rebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆