How to get interdiff between these two git commits?

I am trying to see the difference between two versions of the same commit in git. The difference in differences is mainly. From what I have read so far, this is called "interdiff." I read a few tutorials on how to create interdiffs of git patches, but I was not able to get these methods to work in my particular case.

So here is the setup. I have two diverging branches, each of which has slightly different meanings:

* 29e734f - (origin/feature_branch, new_commits) New commit 3 (69 minutes ago) <Ajedi32> * b22ebea - New commit 2 (89 minutes ago) <Ajedi32> * 09d42c2 - New commit 1 (2 hours ago) <Ajedi32> | * 467e08f - (old_commits) Old commit 3 (4 weeks ago) <Ajedi32> | * f2bf1cb - Old commit 2 (4 weeks ago) <Ajedi32> | * 34a2187 - Old commit 1 (4 weeks ago) <Ajedi32> |/ * 1b05a4a - (origin/base, base) Base commit (5 weeks ago) <Ajedi32> 

In this example, I want to find the interdiff between "Old commit 3" and "New commit 3". I tried to create a patch file from these two commits and run them using the interdiff utility, but all I got was the following:

 1 out of 2 hunks FAILED -- saving rejects to file /tmp/interdiff-1.Kgwx8u.rej interdiff: Error applying patch1 to reconstructed file 

I'm not quite sure what that means, so I'm stuck right now. Where am I going from here?

Note. I am not looking for git diff old_commits new_commits here. I do not want the changes to make 1 and 2 included in the output.

+4
source share
4 answers

Git 2.19 introduces a new command, git range-diff that does this:

git-range-diff - compares two commit ranges (for example, two versions of a branch)

 git range-diff [--color=[<when>]] [--no-color] [<diff-options>] [--no-dual-color] [--creation-factor=<factor>]\ ( <range1> <range2> | <rev1>...<rev2> | <base> <rev1> <rev2> ) 

Description

This command shows the differences between the two versions of the fix series or, more generally, the two commit ranges (ignoring merge commit).

To do this, he first finds pairs of commits from both ranges of commits that match each other. Two fixes are said to correspond when the difference between their patches (that is, information about the author, a fix message, and a fix difference) is small enough compared to the size of the patches. See Algorithm below for details.

Finally, a list of matching commits is displayed in the order of the second range of commits, and unsurpassed commits are inserted immediately after all their ancestors have been shown.

So in your case:

 git range-diff base old_commits new_commits 

Will automatically match the commits made in the old_commits branch to the old_commits new_commits branch and display a summary of the differences between each commit.

Or, if you just want to get changes from the last commit in each of these branches, you should do:

 git range-diff old_commits~..old_commits new_commits~..new_commits 

For more information on range-diff, see the official documentation .

+2
source

Maybe something like this:

 git log -p -1 new_commits > patch.new git log -p -1 old_commits > patch.old diff patch.old patch.new 

Or for a brief one-liner (in bash ):

 diff <(git log -p -1 old_commits) <(git log -p -1 new_commits) 
+2
source

Perhaps this will give you something like what you want. But it will fail if the 1-2-3 fixes are very dependent.

 $ git checkout 'old commit 2' $ git cherry-pick -n 'new commit 3' $ git diff 'old commit 3' $ git checkout 'new commit 2' $ git cherry-pick -n 'old commit 3' $ git diff 'new commit 3' 
0
source

If there are few differences between the two commits, deleted lines and added lines are compared (i.e. only those starting with + or -). It gets rid of the noise introduced by the hunks borders, starting with @@ or the commit message body, which doesn't matter:

 diff -u --ignore-matching-lines '^[^+-]' \ <(git show 1d9e4ac) <(git show 7b8e5c9) 

output selection:

 --- /dev/fd/63 2015-02-13 13:27:08.612683558 +0100 +++ /dev/fd/62 2015-02-13 13:27:08.616683527 +0100 @@ -62,13 +57,24 @@ } diff --git a/src/crush/CrushWrapper.hb/src/crush/CrushWrapper.h -index 0113662..282cbeb 100644 +index 3b2e6e6..0a633a5 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h -@ @ -874,6 +874,25 @@ public: - return false; +@ @ -863,6 +863,36 @@ public: + if (!crush) return -1; + return crush_find_rule(crush, ruleset, type, size); } - ++ ++ bool ruleset_exists(int const ruleset) const { ++ for (size_t i = 0; i < crush->max_rules; ++i) { ++ if (crush->rules[i]->mask.ruleset == ruleset) { ++ return true; ++ } ++ } ++ ++ return false; ++ } ++ + /** + * Return the lowest numbered ruleset of type `type` + * 
0
source

Source: https://habr.com/ru/post/1492750/


All Articles