Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git log after git merge --no-ff shows all commits from the other branch merged

Tags:

git

merge

I read documentation about git merge --no-ff.

I tried and the result is:

Mini-de-MiniMac:ZtestGit minimac$  git branch
  feature
* master

Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline
82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
50d9f108d70798a13cc25fb7321d57ad5ba61854 three
d7163bc5320162689544293be1ac2228c6e3dc34 two
a7ba4c797d49d940a7d64a8ddaba787eb013622a one
cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start  

Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline --graph
*   82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
|\  
| * 50d9f108d70798a13cc25fb7321d57ad5ba61854 three
| * d7163bc5320162689544293be1ac2228c6e3dc34 two
| * a7ba4c797d49d940a7d64a8ddaba787eb013622a one
|/  
* cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start    

I'm surprised about that and I don't understand: git log on the master branch show all commits (one, two, three) but these commits are on the feature branch, not master.

I understand the last commit on the master branch is the descendant of a chain of previous commits on the feature branch. I expected to have like a rebase on the master branch and to see only the first and last commits on master. Could you explain to me why it is different please?

So the interest to do git merge --no-ff is to work with git log --graph and not git log only?

I add a even stranger phenomenon: when i delete the feature branch, git says the branch is deleted but git log and git log --graph give exactly the same result as before : commits and feature branch still appear.
Do you have an explanation?

Mini-de-MiniMac:ZtestGit minimac$  git branch
  feature
* master

Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline
82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
50d9f108d70798a13cc25fb7321d57ad5ba61854 three
d7163bc5320162689544293be1ac2228c6e3dc34 two
a7ba4c797d49d940a7d64a8ddaba787eb013622a one
cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start
Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline --graph
*   82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
|\  
| * 50d9f108d70798a13cc25fb7321d57ad5ba61854 three
| * d7163bc5320162689544293be1ac2228c6e3dc34 two
| * a7ba4c797d49d940a7d64a8ddaba787eb013622a one
|/  
* cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start
Mini-de-MiniMac:ZtestGit minimac$ git branch
  feature
* master  


Mini-de-MiniMac:ZtestGit minimac$ git branch -d feature
Deleted branch feature (was 50d9f10).  

Mini-de-MiniMac:ZtestGit minimac$ git branch
* master

Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline
82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
50d9f108d70798a13cc25fb7321d57ad5ba61854 three
d7163bc5320162689544293be1ac2228c6e3dc34 two
a7ba4c797d49d940a7d64a8ddaba787eb013622a one
cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start

Mini-de-MiniMac:ZtestGit minimac$  git log --pretty=oneline --graph
*   82307080064b764c28622351a4c28abb4f9302b8 Merge branch 'feature' with --no-ff option
|\  
| * 50d9f108d70798a13cc25fb7321d57ad5ba61854 three
| * d7163bc5320162689544293be1ac2228c6e3dc34 two
| * a7ba4c797d49d940a7d64a8ddaba787eb013622a one
|/  
* cc3e4abf5dfad7779de3837a6c4e6e29e3ca87b2 start

Thanks.

like image 818
Beretta Avatar asked Mar 10 '23 20:03

Beretta


2 Answers

Use can use

git log --first-parent

to see the commits made only into the branch you are currently in. (I understand that commits are not "on" any branch, as the previous answer says)

like image 111
Aris totle Avatar answered Mar 14 '23 06:03

Aris totle


Git log shows all commits that are ancestors of the ref you specify. The presence or absence of other branches has no effect. It walks the commit graph.

these commits are on the feature branch, not master

Commits in git are not "on" any branch. A branch is a movable pointer that names a commit (and by extension, all the ancestors of that commit).

By merging your feature branch into master -- either by fast-forward or by a merge -- you move the branch pointer of master to some commit new to that branch. This commit has the previous commit that was on master as an ancestor.

So the interest to do git merge --no-ff is to work with git log --graph and not git log only?

The value in specifically creating a merge commit is to record what was merged, and when, and by whom. A git repository stores history only in the commit graph, the branches are ephemeral.

like image 38
Josh Lee Avatar answered Mar 14 '23 07:03

Josh Lee