gpt4 book ai didi

git - rebase Git merge 提交

转载 作者:IT王子 更新时间:2023-10-29 01:18:09 27 4
gpt4 key购买 nike

以下面的例子为例:

我在主题分支中有一些工作,现在我已准备好 merge 回主分支:

* eb3b733 3     [master] [origin/master]
| * b62cae6 2 [topic]
|/
* 38abeae 1

我从 master 执行 merge ,解决冲突,现在我有:

*   8101fe3 Merge branch 'topic'  [master]
|\
| * b62cae6 2 [topic]
* | eb3b733 3 [origin/master]
|/
* 38abeae 1

现在, merge 花了我一些时间,所以我又做了一次抓取并注意到远程主分支有新的变化:

*   8101fe3 Merge branch 'topic'  [master]
|\
| * b62cae6 2 [topic]
| | * e7affba 4 [origin/master]
| |/
|/|
* | eb3b733 3
|/
* 38abeae 1

如果我从 master 尝试 git rebase origin/master,我将被迫再次解决所有冲突,并且我也会丢失 merge 提交:

* d4de423 2       [master]
* e7affba 4 [origin/master]
* eb3b733 3
| * b62cae6 2 [topic]
|/
* 38abeae 1

是否有一种干净的方法来重新设置 merge 提交的基数,以便我最终得到如下所示的历史记录?

*   51984c7 Merge branch 'topic'  [master]
|\
| * b62cae6 2 [topic]
* | e7affba 4 [origin/master]
* | eb3b733 3
|/
* 38abeae 1

最佳答案

这里有两个选项。

一种是进行交互式 rebase 并编辑 merge 提交,手动重做 merge 并继续 rebase 。

另一种是在git rebase上使用--rebase-merges选项,手册中是这样描述的:

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."

关于git - rebase Git merge 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4783599/

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