Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a cumulative git diffs for multiple non-consecutuve commits

Tags:

git

github

diff

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.

like image 874
DDS Avatar asked Aug 09 '16 05:08

DDS


People also ask

How do you squash non continuous commits?

You can run git rebase --interactive and reorder D before B and squash D into A. And git will now meld the changes of A and D together into one commit, and put B and C afterwards. When you don't want to keep the commit message of D, instead of squash , you would use the fixup keyword.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.

How do you squash random commits?

Git's squash commits command There is no explicit Git squash command. Instead, to squash git commits, the interactive git rebase is used. To squash all commits on a single branch, the interactive git rebase command must be passed one of two arguments: the id of the commit from which the branch split from its parent.

How does git calculate diffs?

The diff is dynamically generated from the snapshot data by comparing the root trees of the commit and its parent. Git can compare any two snapshots in time, not just adjacent commits. To compare two commits, start by looking at their root trees, which are almost always different.


1 Answers

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

like image 143
DavidN Avatar answered Oct 28 '22 02:10

DavidN