首页 > git > 在git merge之后,在git log graph中保持分支的提交历史记录

在git merge之后,在git log graph中保持分支的提交历史记录 (Keep commit history of a branch in git log graph after git merge)

问题

测试用例:

                 A---B---C topic
                /
           D---E master

如果我做

git checkout master
git merge topic

我去拿


               D---E---A---B---C master,topic

如何合并以使提交图保持如下所示

                     A---B---C topic
                    /         \
               D---E-----------F master

解决方法

对于一次性方法,你可以做到

git merge topic --no-ff

它将强制合并提交(参见doc)。


但另请注意,如果您需要在回购中将其作为常规工作流程的一部分,则可以在配置中将其设置即使在可能的情况下也不会快进合并

git config merge.ff false

问题

Test case:

                 A---B---C topic
                /
           D---E master

If I do

git checkout master
git merge topic

I'll get


               D---E---A---B---C master,topic

How can I merge so that the commit graph remains like the following

                     A---B---C topic
                    /         \
               D---E-----------F master

解决方法

For a one-shot approach, you can do

git merge topic --no-ff

and it will force the merge commit (see doc).


But also note that if you need to have that on a repo as part of your general workflow, you can set it in your config to never fast-forward merge even when possible, with

git config merge.ff false
相似信息