I do not understand the behavior of git merge
. Sometimes, I merge a branch and, after executing git log --graph
, I can see the branch merging as a draw like:
D
/ \
C B
\ /
A
I just did
$ git merge feature1 develop
Updating 4c3dd3e..a90a849 Fast-forward
fileA.txt | 1 + 1 file changed, 1 insertion(+)
It works. I can even delete the topic branch which shows the branch is not indispensable anymore and the merge was successful:
$ git branch -d feature1
Deleted branch feature1 (was a90a849).
However, I cannot see the drawing. I just have a line:
pedro (develop) second-final-project $ git log --graph
* commit a90a84966040e36b994c0146bbd8a666954bee49 (HEAD -> develop)
| Author: Pedro Delfino <p.delfino01@gmail.com>
| Date: Fri Jul 16 12:29:24 2021 -0300
|
| add feature 1
|
* commit 4c3dd3ea0cfe07e1c9ccd9e65b2a2060137f1b27
| Author: Pedro Delfino <p.delfino01@gmail.com>
| Date: Fri Jul 16 11:49:00 2021 -0300
|
| add fileA.txt
|
* commit ae8124ea03436dd48d98424d594ff91b75bca00b (master)
Author: Pedro Delfino <p.delfino01@gmail.com>
Date: Fri Jul 16 11:48:33 2021 -0300
add README.md
Maybe the drawing is not visible because of a fast-forward commit. But I think I have seen the drawing and the merge commit in fast-forward merges before.
In addition, I was expecting to see something different as commit messages. I got the commit message available as the last commit on the merged branch.
I would like to see the merge commit with that standard message, such as:
Merge branch 'feature1' into develop
Sometimes this desired message naturally happens. In other situations, it does not, such as the present one.
Why does this happen? How can I achieve the standard message and the visual drawing desired when merging a branch?
Thanks.
That's because there was no real merge there. Git simply moved from the position you were to the position of the branch you were merging (what's called a fast-forward
). That is because there is no real divergence between the two branches The revision where you were is one ancestor of the branch you are merging so git avoids the merge. In this case, if you want to really see a merge revision, you need to run git merge --no-ff