1

This may be a fairly simple problem with how I'm using git or how I'm integrating it with Visual Studio 2012. I have (or thought I had) two major branches: master and develop.

I rarely touch the master branch, I mostly make commits to the develop branch and when I reach a milestone I merge the develop branch with the master branch. If I'm introducing a new feature, I make a new branch feat/SomeFeature off from the develop branch. When that feature is done, I merge that with the develop branch and then merge that with the master branch.

Switching branches does exactly what I expect it to do, I see the old untouched versions of the code. However, when I open the repo in a branch visualisation program it appears that all my commits are all along one branch:

enter image description here

I was expecting to see loops and merges, like in this screenshot: enter image description here

Why do my branches appear different? Why do all my commits appear along one branch?

Tim
  • 41,901
  • 18
  • 127
  • 145
RamblerToning
  • 926
  • 2
  • 13
  • 28
  • Can you try one of the built-in visualization tools and see if it agrees with what you see with Git Extensions? `gitk --all` or `git log --all --graph --decorate` should work from a console (assuming you've got `git` in your path). – ChrisGPT was on strike Apr 15 '14 at 11:51
  • I ran git log --all --graph --decorate and it does seem to agree with what Git Extensions displays. http://i.imgur.com/bYwZxW1.png I wasn't doubting Git Extensions, I think I must be doing something wrong in my branches but I don't understand what. – RamblerToning Apr 15 '14 at 11:56

1 Answers1

1

What's going on

It's hard to know exactly what's going on without more information, but you are probably getting fast-forward merges. Basically, if Git can flatten a merge it defaults to doing so. Your workflow of working primarily in develop and merging that repeatedly into master predisposes you to fast-forward merges.

(Note that there is nothing inherently wrong with fast-forward merging. Some developers love this flow and go out of their way to only use this merge strategy by rebaseing their work before merging. Other developers, myself included, like to see "merge bubbles" for feature merges.)

As an example, consider the following commit graph:

[master]   A---B---C
                    \
[develop]            D---E---F

master contains commits A, B and C. develop contains commits A, B, C, D, E, and F.

At this point, if you merge develop into master Git will default to a fast-forward merge, resulting in

[master] [develop] A---B---C---D---E---F

This happens because the merge would logically result in the same commits existing in both trees: You are merging commits D, E and F onto a branch that already contains A, B and C.

If the previous graph looked different, for example

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

something different would happen. You would end up with something like this:

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

In this case you get a new commit H, which is called a merge commit.

Keeping merge bubbles

You can force the latter behaviour using the --no-ff flag to git merge. (There is also a --ff-only flag to force the opposite behaviour.) From the first example a git checkout master && git merge --no-ff develop would result in something like this

[master]   A---B---C-----------G
                    \         /
[develop]            D---E---F

Note the new merge commit G.

Visual Studio

This is all from the perspective of Git on the command-line, but I note that you are using Visual Studio. I am not sure how to trigger the --no-ff option to merge from VS, assuming you are performing your merges from that tool. Sadly, many graphical Git clients hide very useful options like this flag.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • I think this might explain it! Is this a flag I can set in the git config file? I think it could be something I could add to [merge] ff = false ? – RamblerToning Apr 15 '14 at 12:27
  • Yes, this was precisely when the issue! When I use Git Extensions to make the commits and merges and explicitly tell it to not use fast-forward merges, it displays the loops that I was anticipating. Thank you! – RamblerToning Apr 15 '14 at 12:34
  • @mortenalbring, glad it helped. [You can make `--no-ff` the default *per branch*](http://stackoverflow.com/questions/2500296/can-i-make-fast-forwarding-be-off-by-default-in-git). Edit: [It looks like there is now a sorta-kinda-default way to set this](http://stackoverflow.com/a/6810687/354577). – ChrisGPT was on strike Apr 15 '14 at 12:57