bob.sacamento bob.sacamento - 16 days ago 5
Git Question

git merging and log message

I'm still learning my way around git. Before a merge, git log was telling me something like ....

commit 9588d21a81d0f8a977c8d0651eee9f56eaf4186d
Merge: 0367c67 fbd02fc
Author: me <me@here.there.com>
Date: Thu Nov 17 17:09:25 2016 -0600

On branch branch1

...


I wanted to merge branch1 with branch0, so I issued the merge command:

> git checkout branch0
> git merge branch1


To my surprise, it went without a hitch. Output looked something like:

Updating e57618a..9588d21
Fast-forward
src/file1.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
src/blah.h | 15 +++-
src/file2.c | 2 -
src/main.c | 91 +++++++++++++++++------
...

11 files changed, 811 insertions(+), 100 deletions(-) ...


No conflicts or anything AFAICT. However, when I issue a git log command, there is no indication of this merge having taken place, and the old commit in branch1 is still at the top of the log:

commit 9588d21a81d0f8a977c8d0651eee9f56eaf4186d
Merge: 0367c67 fbd02fc
Author: me <me@here.there.com>
Date: Thu Nov 17 17:09:25 2016 -0600

On branch branch1

...


Is this the behavior I should expect? I was expecting at least that the branch would now be shown as branch0. What happens at this point if I attempt to delete branch1?

Answer

Based on your comments, it looks like git performed a simple fast-forward merge. Basically you made one or more commits in branch1 and then merged that branch back into branch0, so git simply moved the pointer of branch0 to point to the last commit at branch1.

That is a fast-forward merge. Some people don't like that and want to see a explicit merge, in that case you need to use the --no-ff flag when you issue your merge command.

The below figure from the git book may help illustrate this:

two git branches before a fast-forward merge

When git performs a fast-forward merge the branch master (or branch0 in your case) simply moves to point to commit C3. No additional merge commits are created.

If you delete branch1 nothing is lost since branch0 is still pointing to the latest commit that came from branch1. You can verify it by issuing the below command (whilst on branch0).

git branch --merged

It should show branch1, which you can delete with:

git branch -d branch1

Git would issue a warning if you try to delete a non-merged branch anyway, and you would have to force the deletion with -D

Comments