Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff with author filter

Tags:

git

git-diff

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?

like image 442
Samer Buna Avatar asked Aug 18 '10 06:08

Samer Buna


People also ask

How do I find the difference between two commits in git?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

How does git diff work internally?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What does git diff head do?

The git diff HEAD [filename] command allows you to compare the file version in your working directory with the file version last committed in your remote repository. The HEAD in the git command refers to the remote repository.

What is git diff cached?

explainshell.com - git diff --cached. Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk.


1 Answers

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.

like image 93
Cascabel Avatar answered Oct 13 '22 00:10

Cascabel