简体   繁体   English

合并后Git分支并提交历史记录

[英]Git branches & commits history after merge

I'm working on a project (alone) and for every feature I develop I create a new branch, work on this feature, then merge it to master. 我正在开发一个项目(单独),对于我开发的每个功能,我创建了一个新的分支,处理这个功能,然后将它合并到master。 So normally I never work on two different branches at one time and never touch master while working on a branch. 所以通常我一次不会在两个不同的分支上工作,而是在分支机构工作时从不接触主人。

When I merge a branch I see that (using gitx and gitk ) the history of master branch gets all the commits I've done to the merged branch. 当我合并一个分支时,我看到(使用gitxgitk )master分支的历史记录获取了我对合并分支所做的所有提交。 I mean if I have something like: 我的意思是,如果我有类似的东西:

master a-b-c-d
              \z-x-y--
              |branch name

after merge I get: 合并后我得到:

a-b-c-d-z-x-y
            |branch name

Yes, I see the merged branch name highlighted (using gitx and gitk ), but what I was expecting is something showing exactly where commits are done (to which branch) like: 是的,我看到合并的分支名称突出显示(使用gitxgitk ),但我所期待的是显示提交完成的位置(到哪个分支),如:

master a-b-c-d--------M--
              \-z-x-y-/
              |branch name

So I'm expecting to see a commit "M" that represents the merge I've done to master, not to look like that all commits I've done to the new branch have been done to master. 所以我期待看到提交“M”代表我已经完成的合并,而不是看起来我已经完成了对新分支所做的所有提交。

Is my expectation correct? 我的期望是否正确? Or this is normal git behaviour? 或者这是正常的git行为?

That is normal Git behaviour. 这是正常的Git行为。 You are doing what is called a "fast-forward" merge, because your branch is strictly ahead of the master branch. 您正在进行所谓的“快进”合并,因为您的分支严格地位于master分支之前。

If you really want to preserve branch history (although I'd recommend you don't bother) then you can use git merge --no-ff to force it to create a merge commit even when it can do a fast-forward update. 如果你真的想保留分支历史(虽然我建议你不要打扰),那么你可以使用git merge --no-ff强制它创建一个合并提交,即使它可以进行快进更新。

You can found addition criticism to the -no-ff option in " Understanding the Git Workflow ", mainly because it would break git blame . 您可以在“ 了解Git工作流 ”中找到对-no-ff选项的额外批评,主要是因为它会破坏git blame
More at " fast forward when using pull and no-ff when pull ". “更多的使用快进时pullno-ffpull ”。

As explained in " Why does git use fast-forward merging by default? ", unless you are talking about a really long-lived branch, a fast-forward merge is preferable. 正如“ 为什么git默认使用快进合并? ”中所解释的那样,除非你谈论的是一个非常长寿的分支,否则快进合并更可取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM