我有以下最近的提交历史记录:
* 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)
| | |
它说明了baz
文件的创建历史。它以foo
开头,由拉请求添加。然后将其重命名为bar
。另一个拉取请求还引入了bar
文件,并将其合并到现有的bar
中。然后将其重命名为baz
并合并到主分支。
我试图列出baz
文件的完整历史记录(这是上面树中的每个提交),因此我可以通过编程方式获取文件的贡献者。以下是我的尝试:
$ git log --oneline -- baz
a022556 Rename 'bar' to 'baz'
没有超过文件名,所以我需要--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)
通过文件重命名,但只跟随从foo
开始的父项,并且不包括将更改合并到bar
。特别是,缺少提交fdc3e37
,其自身版本的bar
已合并。--all
或--full-history
都不会更改任何内容。
$ git log --follow --merges --oneline -- baz
添加--merges
似乎根本没有结果。
这就是我所期待的(提交顺序和合并提交真的很重要):
$ 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)
有没有办法解决这个问题?
答案 0 :(得分:1)
似乎可以使用--simplify-merges
选项解决:
$ 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)
这不包括合并,但这对我的具体情况没有问题。
虽然手册页没有让我知道这是如何工作的:
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.
我不明白为什么会影响这里的结果。