Skip to content

Instantly share code, notes, and snippets.

@lava
Last active November 21, 2018 13:54
Show Gist options
  • Save lava/8d0fd58a871c47bd7f5ba5445a084f50 to your computer and use it in GitHub Desktop.
Save lava/8d0fd58a871c47bd7f5ba5445a084f50 to your computer and use it in GitHub Desktop.
Git history and merge commits
# Testing the `--no-ff` merge strategy
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.
## Behaviour of `HEAD`
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`.
## Viewing the contents of commits
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.
## Bisecting on merge commits
I wanted to try this as well since it came up in the comments, but
I don't know how to do it. Suggestions?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment