1

Could someone explain, why in a situation like this:

A--B--C--D  (master)
    \
     \E--F  (feature/xxx, feature/xxx-blah)

if I do a merge feature/xxx-blah into master, the branch pointer doesn't actually move? The commit is there, master pointer is advanced, but both features point at the same commit F.

I expected to end up with this instead:

A--B--C--D--G  (master, feature/xxx-blah)
    \      /
     \E--F/  (feature/xxx)
viraptor
  • 30,857
  • 7
  • 96
  • 176
  • 3
    if you pour sugar into your coffee, do you expect that the sugar will then have coffee in it; no, what you get is coffee with sugar in it. (replace coffee with master branch and sugar with feature branch). – Dan D. Sep 26 '11 at 09:39
  • @DanD. That's excellent - I must try to remember that analogy :) – Mark Longair Sep 26 '11 at 09:51

2 Answers2

3

This is working as designed - when you merge, you only advance your current branch. This is actually a useful property, since if instead it worked as you expected, you then wouldn't easily be able to tell what was just on your feature branch after you had merged it - master and feature/xxx-blah would contain exactly the same commits.

In most cases ("porcelain" commands in particular), actions in git that create new commits will advance your current branch, but won't advance any other branches as side-effects.

One other point that might be worth making is that you can merge from any commit (or more than one) - they don't have to be branches.

Mark Longair
  • 385,867
  • 66
  • 394
  • 320
  • Ok, I see. For some reason I was under impression that merging features actually moved the feature pointer in all cases. I have no idea why (yes, I was doing no-ff merges). Must have more coffee.... :( – viraptor Sep 26 '11 at 09:49
0

The fact that you comment doing no-ff merges explains why you expected:

A--B--C--D--G  (master, feature/xxx-blah)
    \      /
     \E--F/  (feature/xxx)

But as mentioned in "Why does git use fast-forward merging by default?", no-ff is not the default.
You see a similar scenario in "Moving master head to a branch".

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283