简体   繁体   English

Git日志分支拆分

[英]Git log branches splitting

I've been doing some work on a project managed with git. 我一直在用git管理的项目上做一些工作。 At some point I created a branch with 在某个时候我创建了一个分支

git -b my-branch

did some work ,commited and pushed to the remote repo. 做了一些工作,承诺并推送到远程仓库。 Later, I merged with: 后来,我合并了:

git checkout master
git merge my-branch
git push

But when i look at the graph with gitlab i do not see the branches splitting, just something like this 但是当我用gitlab查看图时,我看不到分支分裂,就像这样

* * * * * * * 
            ^
            |
         my-branch

When i'd expect something like 当我期望像

* * * * * * *
    \-------^
            |
        my-branch

Why is this ? 为什么是这样 ?

This is probably because of fast-forwarding. 这可能是因为快进。 If Git doesn't need to do a merge, it won't. 如果Git不需要合并,则不需要。 This happens when you merge a branch but have made no changes to its parent. 当您合并分支但未对其父级进行任何更改时,就会发生这种情况。

A - B - C - D - E [master]
                 \
                  F - G - H [feature]

In this repo there have been no changes to master since feature was branches. 由于feature是分支,因此在此版本库中没有对master进行任何更改。 master is an ancestor of feature . masterfeature的祖先。 That apparent branch between E and F isn't really there, the history is straight. E和F之间的明显分支实际上并不存在,历史是直截了当的。

If you git checkout master; git merge feature 如果您git checkout master; git merge feature git checkout master; git merge feature it will "fast-forward" and you'll wind up with this. git checkout master; git merge feature将“快速前进”,您将为此而结束。

                              [master]
A - B - C - D - E - F - G - H [feature]

master is moved to the same commit as feature , no merge is done. master移至与feature相同的提交,不进行任何合并。


You can turn this off with git merge --no-ff . 您可以使用git merge --no-ff关闭此功能。 I recommend this when merging feature branches to avoid losing important information to understand the code. 在合并功能分支时,我建议这样做,以避免丢失重要的信息来理解代码。 In the example above, there's no evidence that F, G, and H were done as a single feature. 在上面的示例中,没有证据表明F,G和H是作为单个功能完成的。 There's no link to the ticket discussing the feature. 没有链接到讨论该功能的票证。

Instead if we had git checkout master; git merge --no-ff feature 相反,如果我们有git checkout master; git merge --no-ff feature git checkout master; git merge --no-ff feature this would force Git to merge even if it didn't have to. git checkout master; git merge --no-ff feature ,即使没有必要,这也会强制Git合并。

A - B - C - D - E ---------- I [master]
                 \         /
                  F - G - H [feature]

I is the merge commit and you get a nice feature bubble. 我是合并提交,您会看到一个漂亮的功能提示框。

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

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