与作者过滤器的git diff [英] git diff with author filter

查看:135
本文介绍了与作者过滤器的git diff的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有不同作者的一系列提交,我希望在2次提交之间看到一个 git dff 输出,但只考虑其中一位作者的提交,就像git log中的--author。



我对最终的summary diff感兴趣,而不是单个提交的差异。 b

有没有git技巧呢?

解决方案

这里的问题是,你不能在一般情况下这样做。假设Alice更改一个特定的文件,那么Bob会更改它 - 包括Alice更改的部分 - 最后Alice再次更改它。你如何将Alice的两个差异结合到一个差异?如果你把它们作为两个补丁,那么如果没有Bob的补丁首先被应用,第二个补丁就不会适用。但是,你也不能简单地将最终状态与原始状态进行比较,因为这将包括Bob的更改。



如果你喜欢使用git操作的例子,这就像做一个互动的重新组织,并且只是删除随机提交。当然,有时候它会起作用,但有时它会完全失败,因为其中一次提交取决于你拿出的一次提交。



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

  git log -p  - -author = Alice 

或者,如果你真的渴望单个差异,这将会得到它你只是在没有像我上面提到的补丁交互的情况下:

  git checkout -b temp first_commit 
git log --pretty =%H --author = Alice first_commit..second_commit |读取提交时
;做
git cherry-pick $ commit ||退出
完成
#或者如果你有一个新版本的git,cherry-pick可以使用多个参数:
#git cherry-pick $(git log --pretty =%H - 作者= Alice first_commit..second_commit)
git diff first_commit temp

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


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?

解决方案

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

这篇关于与作者过滤器的git diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆