2

If a commit was cherry-picked and required a conflict to be resolved:

commit 7b8e5c99a4a40ae788ad29e36b0d714f529b12eb
Author: John Spray 
Date:   Tue May 20 16:25:19 2014 +0100
...
    Signed-off-by: John Spray 
    (cherry picked from commit 1d9e4ac2e2bedfd40ee2d91a4a6098150af9b5df)
    Conflicts:
        src/crush/CrushWrapper.h

is there a way to display the difference between the two commits (i.e. 1d9e4ac and 7b8e5c in the example above) to figure out how the conflict was resolved ?

Loic Dachary
  • 1,034
  • 1
  • 10
  • 24

3 Answers3

2

One way is to redo the cherry-pick to reproduce the conflict.

  • git checkout 7b8e5c99a4a40ae788ad29e36b0d714f529b12eb
  • git cherry-pick -n 1d9e4ac2e2bedfd40ee2d91a4a6098150af9b5df

-n says to not commit, so you can just throw out the work when you're done examining it.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • What I need is not the original conflict but the way it was resolved. – Loic Dachary Feb 15 '15 at 23:21
  • @LoicDachary There is no record of how it was resolved other than the resulting commit (ie. 7b8e5). The conflict markers tell you where to look in the files at 7b8e5. If there was a conflict in the file `some/thing` on lines 120-124 then run `git show 7b8e5c99a4a40ae:some/thing` and look at lines 120-124. – Schwern Feb 15 '15 at 23:24
0

Next time you resolve you conflicts use the build-in git rerere command.
rerere= Reused Recorded Resolution. It will record the way you resolved your conflict like a patch and then you can simply view the output.

here is a detailed post about it.

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
0

The difference between the original commit and the cherry-picked commit including the conflict resolution can be displayed with:

commit=7b8e5c99a4a40ae788ad29e36b0d714f529b12eb
picked_from=$(git show --no-patch --pretty=%b $commit  | 
  perl -ne 'print if(s/.*cherry picked from commit (\w+).*/$1/)')
diff -u --ignore-matching-lines '^[^+-]' \
   <(git show $picked_from) <(git show $commit)

The SHA of the original commit is extracted from the cherry picked commit message. The diff compares the lines removed and lines added (i.e. only those starting with + or -). It gets rid of the noise introduced by the hunks boundaries starting with @@ or the commit message body that are not significant. It will display something like:

--- /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.h b/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`
 +   *
Loic Dachary
  • 1,034
  • 1
  • 10
  • 24