哪种方式进行git合并? [英] which way to git merge?

查看:109
本文介绍了哪种方式进行git合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我想将分支featureBranch的非快进合并(真正的合并",而且绝对不是变基)合并为分支master.为了简单起见,请假设没有远程存储库(只有1个本地存储库),这是git checkout featureBranch && git log的输出:

Let's say that I want to do a non-fast-forward merge (a "real merge" and definitely not a rebase) of a branch featureBranch into a branch master. For the sake of simplicity please assume that there are no remote repositories (there is only 1 local repository), and this is the output of git checkout featureBranch && git log:

Switched to branch 'featureBranch'
commit 486b01a6db4597a8f02c9f23a16ddaa2d0e18392
Author: xxx <xxx@xxx.com>
Date:   Mon Sep 28 21:02:00 2015 +0100

    C

commit 39fde8a6ccd27ad8e5b815f5462ae6267df2e213
Author: xxx <xxx@xxx.com>
Date:   Mon Sep 28 21:00:34 2015 +0100

    A

这是git checkout master && git log的输出:

Switched to branch 'master'
commit 903ad86a4395f004dd2f28009b11f93d4c056d0b
Author: xxx <xxx@xxx.com>
Date:   Mon Sep 28 21:00:54 2015 +0100

    B

commit 39fde8a6ccd27ad8e5b815f5462ae6267df2e213
Author: xxx <xxx@xxx.com>
Date:   Mon Sep 28 21:00:34 2015 +0100

    A

是执行合并的正确方法,如下所示:

Is the right way of carrying out the merge like this:

git checkout master && git merge featureBranch

或类似的话:

git checkout featureBranch && git merge master

请注意,这不是此SO问题的重复项,关于快进合并.

Please note this is not a duplicate of this SO question, which is about a fast-forward merge.

推荐答案

正确的方法是:

git checkout master
git merge featureBranch

原因是父级提交在合并中的顺序很重要,而master始终应该是两者中的第一个.这样可以确保git log --first-parent的行为符合预期.此博客文章中的更多详细信息: http://devblog.nestoria.com/post/98892582763/maintening-a-consistent-linear-history-for-git

The reason is that the order of parent commits in merge is important, and master should always be the first of the two. This makes sure that behaviour of git log --first-parent is as expected. More detail in this blog post: http://devblog.nestoria.com/post/98892582763/maintaining-a-consistent-linear-history-for-git

marcolz提出的方法将破坏日志,因为它创建了2个合并提交,其中第一个具有特征分支的最后一个提交在第一位(应该在第二位).

The method proposed by marcolz would break the log, as it creates 2 merge commits, the first of which has the last commit of feature branch on the first place (it should be on the second).

乔纳森的回答本质上是正确的,但缺乏博客文章中的细节.

Jonathan's answer is essentially correct, but lacks the detail in the blog post.

这篇关于哪种方式进行git合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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