gitgithubdiff

Get cumulative Git diffs for multiple nonconsecutive commits


Is there a way to get a cumulative Git diff for multiple nonconsecutive commits?

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

git diff 123456^ 123456

Where "123456" is a Git hash (SHA-1 hash value).

I can do this for multiple commits. But I now 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.

Let’s 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 two 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 don’t want to commit anything; I just want do this to review code for security.


Solution

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