Git: does ffwd merge preserves all topic branch commits?

156 views Asked by At

Say we have this situation:

       master
         |
A--B--B--D--E--F--G
                  |
                test

Then we merge test into master. Are commits E and F preserved in the new master branch?

That is, does it now lok like this (option A):

                master
                  |
A--B--B--D--E--F--G
                  |
                test

or like this (option B):

          master
            |
A--B--B--D--G
            |
          test

Sorry if this has already been asked, I couldn't find it. Also, the example in ProGit book is with only one commit ahead (in my example that would be E), which doesn't tackle a situation like this.

3

There are 3 answers

1
CharlesB On BEST ANSWER

What happens it option A: commits are preserved. In case of a fast-forward merge the history is not modified at all, only the master branch points at a different commit. That's all.

4
Carl On

You get a fast forward merge (option A) and the reason to begin with is because there is only a single line of commits between master and test before the merge. If there was a branch between master and test, it would not be a fast forward merge any more.

I would suggest reading this for a good overview on how branching and merging works in git - you need to be really clear on how this stuff works when using git.

0
Adam Dymitruk On

Option A is what happens. Sometimes people want to preserve the branch point and will force git to create a new merge commit.

git merge --no-ff test

This depends on the workflow you want to follow for development.