Douglas Gaskell
Douglas Gaskell

Reputation: 10030

Git merge did not merge, just added all commits to master

I merge one branch back into master and there was no merge commit, all the commits from the other branch now look as if they where committed to master.

What I did:

In SourceTree I selected master, selected merge, selected the most recent commit and merged it. It showed I needed to push my 39 commits, so I did. Only then did I realize that there was no merge commit.

How can I reverse this? It's awkward that the commits show as if they where all made to master.

Upvotes: 0

Views: 68

Answers (1)

Dan Lowe
Dan Lowe

Reputation: 56538

If the branches can be merged without a merge commit, the default is to do that. This is known as "fast forward", and the HEAD marker is simply moved to the new commit. No new commit is generated.

If you prefer not to do this, you can force a merge commit with --no-ff.

git merge --no-ff <refspec>

From the git-merge man page:

   --ff
       When the merge resolves as a fast-forward, only update the branch
       pointer, without creating a merge commit. This is the default
       behavior.

   --no-ff
       Create a merge commit even when the merge resolves as a
       fast-forward. This is the default behaviour when merging an
       annotated (and possibly signed) tag.

   --ff-only
       Refuse to merge and exit with a non-zero status unless the current
       HEAD is already up-to-date or the merge can be resolved as a
       fast-forward.

Upvotes: 3

Related Questions