gpt4 book ai didi

git - 当前分支中所有提交的 --preserve-merges 交互式 rebase

转载 作者:太空狗 更新时间:2023-10-29 14:28:54 29 4
gpt4 key购买 nike

似乎已经有一些类似的问题,但没有一个正是我想要的。

假设我有这样的提交历史

* 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 的历史,可能 merge 或编辑一些提交,但我也想更改分支 A 上的第一个提交,并且我还想保留 merge ,以便保留 master 的 merge 进入 A.

我首先凭直觉尝试了 git rebase -i -p xxxxxxxB,但显然那不包括 xxxxxxxB 提交本身。所以另一个尝试是 git rebase -i -p xxxxxxxB^ 确实包含了那个提交,但现在它实际上并没有保留 merge 。

另一个看起来很有希望的选项是 --root,但是这个选项从整个存储库中的第一个提交开始,这也不是我想要的。

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

最佳答案

经过比我认为合理的时间更长的时间,我能够在 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.

我还错过了文档中说不要将 -p-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).

关于git - 当前分支中所有提交的 --preserve-merges 交互式 rebase ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51127471/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com