DDS
DDS

Reputation: 179

Get a cumulative git diffs for multiple non-consecutuve commits

I'd like to know if there's a way to get a cumulative git diff for multiple non-consecutive commits.

For an example, I can get a what changed in each commit using:

git diff 123456^ 123456

Where "123456" is a git hash.

I can go this for multiple commits. But I now I want to do multiple diffs and combine the output into one.

For an example,

git diff 123456^ 123456
git diff abcdef^ abcdef

But combine the diff into one. But "123456" and "abcdef" are not consecutive commits.

Update: Lets say a line in file xyz changed:

In commit 123456: from "foo" to "bar"
in commit abcdef: from "bar" to "oof"

I just want to see that it changed from "foo" to "oof" after these to commits.

git diff 123456 abcdef does not work for me because I don't want to all the changes in between 123456 and abcdef.

I dont want to commit anything; just want to this to review code for security.

Upvotes: 16

Views: 3503

Answers (2)

David Neiss
David Neiss

Reputation: 8237

I'm sure someone has a more clever approach, but you could try to squash all your chosen commits down into one and then do the diff on that one. You could do that by doing --cherry-pick with --no-commit. Once you have the final result, you can git diff HEAD to get the diff of that with your base version (assuming you reset yourself to that spot).

Upvotes: 4

ElpieKay
ElpieKay

Reputation: 30966

git diff <commit-A> <commit-B> can generate the diff between A and B, even if A and B are on different branches or from different repos.

Upvotes: -4

Related Questions