Reputation: 110658
I have the following recent commit history:
* cb14273 Merge 'test-branch' into 'master'
|\
| * a022556 Rename 'bar' to 'baz'
| * 6489f33 Merge 'pull-request-bar-branch' into 'test-branch'
| |\
| | * fdc3e37 Added 'bar' file (pull-request-bar-branch)
| * | 3e87596 Rename 'foo' file to 'bar'
| * | 259c0fe Merge 'pull-request-foo-branch' into 'test-branch'
| |\ \
|/ / /
| * | 09e7a1b Added 'foo' file (pull-request-foo-branch)
| | |
It illustrates the history of how the baz
file was created. It started as foo
, which was added by a pull request. It was then renamed to bar
. Another pull request also introduced a bar
file and this was merged into the existing bar
. It was then renamed to baz
and merged into the master branch.
I'm trying to list the full history of the baz
file (which is every commit in the above tree) so I can programmatically get the file's contributors. Here are my attempts:
$ git log --oneline -- baz
a022556 Rename 'bar' to 'baz'
Doesn't get past the file name, so I need --follow
.
$ git log --follow --oneline -- baz
a022556 Rename 'bar' to 'baz'
3e87596 Rename 'foo' file to 'bar'
09e7a1b Added 'foo' file (pull-request-foo-branch)
Gets past the file rename, but only follows the parents starting at foo
, and doesn't include the merge of changes into bar
. In particular, commit fdc3e37
is missing, whose own version of bar
was merged in. Neither --all
or --full-history
change anything.
$ git log --follow --merges --oneline -- baz
Adding --merges
seems to give no results at all.
This is what I'm expecting (the order of commits and the merge commits on't really matter):
$ git log [some options] -- baz
cb14273 Merge 'test-branch' into 'master'
a022556 Rename 'bar' to 'baz'
6489f33 Merge 'pull-request-bar-branch' into 'test-branch'
fdc3e37 Added 'bar' file (pull-request-bar-branch)
3e87596 Rename 'foo' file to 'bar'
259c0fe Merge 'pull-request-foo-branch' into 'test-branch'
09e7a1b Added 'foo' file (pull-request-foo-branch)
Is there any way to get this?
Upvotes: 4
Views: 83
Reputation: 110658
It appears to be solved by using the --simplify-merges
option:
$ git log --follow --simplify-merges --oneline -- baz
a022556 Rename 'bar' to 'baz'
fdc3e37 Added 'bar' file (pull-request-bar-branch)
3e87596 Rename 'foo' file to 'bar'
09e7a1b Added 'foo' file (pull-request-foo-branch)
This doesn't include the merges, but that's okay for my particular case.
Although the man pages don't give me any idea how this works:
Default mode
Simplifies the history to the simplest history explaining the final state of the tree.
Simplest because it prunes some side branches if the end result is the same (i.e. merging
branches with the same content)
--full-history
Same as the default mode, but does not prune some history.
--simplify-merges
Additional option to --full-history to remove some needless merges from the resulting
history, as there are no selected commits contributing to this merge.
I can't see why that would affect the result here.
Upvotes: 1