I created a sample git repository by creating branches
second
and third
adding a file with the same name
each, and then rebasing the branches and merging them
using git merge --no-ff
:
bevers@poincare:~/code/git$ ls
initial second third
bevers@poincare:~/code/git$ git log --graph --oneline
* 044c523 (HEAD -> master) Merge branch 'third'
|\
| * 080a881 Third.
|/
* ab286d7 Merge branch 'second'
|\
| * 8e5204a Add second.
|/
* 66ee9d4 (first2) Initial.
Below I list several observations.
bevers@poincare:~/code/git$ git log --oneline
044c523 (HEAD -> master) Merge branch 'third'
080a881 Third.
ab286d7 Merge branch 'second'
8e5204a Add second.
66ee9d4 Initial.
bevers@poincare:~/code/git$ git show --oneline HEAD~1
ab286d7 Merge branch 'second'
I would have expected HEAD~1
to point at 080a881
.
bevers@poincare:~/code/git$ git log --stat --oneline
044c523 (HEAD -> master) Merge branch 'third'
080a881 Third.
third | 0
1 file changed, 0 insertions(+), 0 deletions(-)
ab286d7 Merge branch 'second'
8e5204a Add second.
second | 0
1 file changed, 0 insertions(+), 0 deletions(-)
66ee9d4 (first2) Initial.
initial | 0
1 file changed, 0 insertions(+), 0 deletions(-)
bevers@poincare:~/code/git$ git log --stat --oneline --merges
044c523 (HEAD -> master) Merge branch 'third'
ab286d7 Merge branch 'second'
bevers@poincare:~/code/git$ git log -p --oneline --merges
044c523 (HEAD -> master) Merge branch 'third'
ab286d7 Merge branch 'second'
This also has implications for tasks like finding out the PR in
which a particular file was last touched: Because the merge
commit itself does not change the file, it does not show up in
git blame
etc. and we would have to walk the log in reverse
direction to get the PR number:
bevers@poincare:~/code/git$ git log --oneline -- second
8e5204a Add second.
I wanted to try this as well since it came up in the comments, but I don't know how to do it. Suggestions?