带有作者过滤器的 git diff
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3509419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git diff with author filter
提问by Samer Buna
I have a series of commits by different authors and I would like to see a git dff
output between 2 commits but only considering the commits by one of the authors, something like, something like --author in git log.
我有不同作者的一系列提交,我希望看到git dff
2 个提交之间的输出,但只考虑其中一个作者的提交,例如 git log 中的 --author 之类的东西。
I am interested in the final summary diff and not the diffs of the individual commits.
我对最终摘要差异感兴趣,而不是单个提交的差异。
Is there a git trick for that?
有一个 git 技巧吗?
采纳答案by Cascabel
The problem here is that you can't do this in the general case. Suppose Alice changes a particular file, then Bob changes it - including parts that Alice changed - and finally Alice changes it again. How do you combine Alice's two diffs into a single diff? If you take them as two patches, the second simply won't apply without Bob's patch being applied first! But you also can't simply diff the final state against the original, because that will include Bob's changes.
这里的问题是在一般情况下你不能这样做。假设 Alice 更改了一个特定文件,然后 Bob 更改了它——包括 Alice 更改的部分——最后 Alice 再次更改了它。你如何将 Alice 的两个差异合并为一个差异?如果您将它们视为两个补丁,那么如果不先应用 Bob 的补丁,则第二个补丁将无法应用!但是您也不能简单地将最终状态与原始状态进行比较,因为这将包括 Bob 的更改。
If you prefer an example with git operations, this is like doing an interactive rebase, and just deleting random commits. Sure, sometimes it'll work, but sometimes it'll just completely fail, because one of those commits depended on one of the ones you took out.
如果你更喜欢 git 操作的例子,这就像做一个交互式 rebase,只是删除随机提交。当然,有时它会起作用,但有时它会完全失败,因为其中一个提交取决于您取出的提交之一。
So, I know you said you don't want individual commit diffs, but that's all you can really hope for:
所以,我知道你说过你不想要单独的提交差异,但这就是你真正希望的:
git log -p --author=Alice
Or if you're really desperate for a single diff, this will get it for you, but only in the cases where there's no patch interaction like I mentioned above:
或者,如果您真的非常渴望单个差异,这将为您提供,但仅在没有我上面提到的补丁交互的情况下:
git checkout -b temp first_commit
git log --pretty=%H --author=Alice first_commit..second_commit |
while read commit; do
git cherry-pick $commit || exit
done
# or if you have a new version of git, cherry-pick works with multiple arguments:
# git cherry-pick $(git log --pretty=%H --author=Alice first_commit..second_commit)
git diff first_commit temp
This does really require operations in the work tree, because there's absolutely no guarantee that any of the patches will apply once a commit has been skipped. You just have to try and see.
这确实需要在工作树中进行操作,因为绝对不能保证一旦跳过提交就会应用任何补丁。你只需要尝试看看。
回答by VonC
May be you could use the formatting features of diff-tree
也许你可以使用diff-tree的格式化功能
format:<string>
The
format:<string>
format allows you to specify which information you want to show.
It works a little bit likeprintf
format, with the notable exception that you get a newline with%n
instead of\n
.E.g,
该
format:<string>
格式允许您指定要显示的信息。
它的工作原理有点像printf
格式,但值得注意的例外是你得到一个换行符%n
而不是\n
.例如,
format:"The author of %h was %an, %ar%nThe title was >>%s<<%n"
would show something like this:
会显示如下内容:
The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
You can then grep on the relevant author.
然后,您可以对相关作者进行 grep。