带有作者过滤器的 git diff

发布于 2024-09-15 00:02:15 字数 131 浏览 4 评论 0原文

我有一系列不同作者的提交,我希望看到两次提交之间的 git dff 输出,但只考虑其中一位作者的提交,例如 git 中的 --author日志。

我对最终的摘要差异感兴趣,而不是各个提交的差异。

有 git 技巧吗?

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.

I am interested in the final summary diff and not the diffs of the individual commits.

Is there a git trick for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

清旖 2024-09-22 00:02:20

也许您可以使用 diff 的格式化功能-树

format:<string>

format: 格式允许您指定要显示的信息。
它的工作方式有点像 printf 格式,但值得注意的例外是您会得到一个带有 %n 的换行符,而不是 \n

例如,

format:"The author of %h was %an, %ar%nThe title was >>%s<<%n" 

会显示类似这样的内容:

The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<

然后您可以 grep 查找相关作者。

May be you could use the formatting features of diff-tree

format:<string>

The format:<string> format allows you to specify which information you want to show.
It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n.

E.g,

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.

谁把谁当真 2024-09-22 00:02:19

git log -p --author=bla | git log -p --author=bla | git log -p --author=bla |差异统计

git log -p --author=bla | diffstat

白况 2024-09-22 00:02:18

这里的问题是在一般情况下你不能这样做。假设爱丽丝更改了一个特定文件,然后鲍勃更改了它 - 包括爱丽丝更改的部分 - 最后爱丽丝再次更改了它。如何将 Alice 的两个差异合并为一个差异?如果您将它们视为两个补丁,那么如果不先应用 Bob 的补丁,第二个补丁就不会应用!但您也不能简单地将最终状态与原始状态进行比较,因为这将包括 Bob 的更改。

如果您更喜欢 git 操作的示例,这就像进行交互式变基,并且只是删除随机提交。当然,有时它会起作用,但有时它会完全失败,因为其中一项提交依赖于您删除的提交之一。

所以,我知道你说过你不想要单独的提交差异,但这就是你真正希望的:

git log -p --author=Alice

或者如果你真的非常渴望单个差异,这将为你提供它,但只有在存在的情况下没有像我上面提到的那样的补丁交互:

git checkout -b temp first_commit
git log --reverse --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 --reverse --pretty=%H --author=Alice first_commit..second_commit)
git diff first_commit temp

这确实需要在工作树中进行操作,因为一旦跳过提交,绝对不能保证任何补丁都会应用。你只需要尝试看看。

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.

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.

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 --reverse --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 --reverse --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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文