--preserve-合并当前分支中所有提交的交互式rebase

时间:2018-07-01 22:36:09

标签: git rebase git-rewrite-history

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

假设我有这样的提交历史

0.17.0

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

我首先凭直觉尝试了* 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 ,但显然,其中不包括xxxxxxxB提交本身。因此,另一次尝试是git rebase -i -p xxxxxxxB,其中确实包含该提交,但现在实际上并没有保留合并。

另一个看起来很有希望的选择是git rebase -i -p xxxxxxxB^,但这是从整个存储库中的第一次提交开始的,这也不是我想要的。

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

1 个答案:

答案 0 :(得分:4)

经过比我认为合理的时间,我能够在irc上找到解决方案:

[object HTMLElement]正是我所需要的。

来自git文档:

git rebase -i -m -r firstCommitInBranch^

   -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. 一起使用-p

-i