Last Updated: February 25, 2016
·
724
· klj613

Understanding git merges

There are two types of merges...

  • FastForward merge
  • Non-FastForward merge.

What does that even mean?!

FF is the default however git will use a non-FF if FF isn't possible.

o-o-o-o-o master
         \
          -o-o-o-o-o-o feature-x

With the above example... since feature-x contains everything master got... merging feature-x into master, FastForward is possible (therefore is the default).

  • git merge feature-x or
  • git merge feature-x --ff-only

will:

o-o-o-o-o
         \
          -o-o-o-o-o-o feature-x | master

git merge feature-x --no-ff will:

o-o-o-o-o--------------o master
         \            /
          -o-o-o-o-o-o feature-x

If master have been updated...

o-o-o-o-o-o-o-o-o master
         \
          -o-o-o-o-o-o feature-x

Then a merge is cannot FastForward.

  • git merge feature-x or
  • git merge feature-x --no-ff

will:

o-o-o-o-o-o-o-o-o------o master
         \            /
          -o-o-o-o-o-o feature-x

git merge feature-x --ff-only will throw an error beacuse it cannot use a FastForward merge.

Note

git merge feature-x --ff-only is the same as git reset feature-x --hard however the merge would throw a error if feature-x doesn't contain everything your current branch has... whilst the reset you may lose commits.