2

I rebased my feature branch over master and want to verify that I resolved all merge conflicts correctly.

I'm using git range-diff for that purpose:

git range-diff --dual-color  old-master..origin/my-branch new-master..my-branch

I've read the documentation trice, but still I'm having trouble understanding the output of range-diff. I'd appreciate if someone could help me with that.

I'm having trouble understanding diffs like this

 6:  1273567d876 !  6:  789a6775664 A-commit-message
    @@ Commit message
     
      ## some/path/something.php ##
     @@ some/path/something.php: function initTexts() {
    -             "text-a",
    -             "text-b",
    -             "text-c",
    +             "text-x",
    +             "text-y",
    +             "text-z",
     +            "text-added-in-the-commit-a",
     +            "text-added-in-the-commit-b",
              ] as $key) {
              

Note that

  1. the first three lines are dimmed and the - has a red background,
  2. the next three lines are bold and the - has a green background,
  3. and the last two lines are green, with no background

The way I read the documentation

  1. should indicate a line that was removed in the first commit range
  2. should indicate a line that was added in the second commit range
  3. should indicate a line that was added in both commit ranges

What I do not understand

  1. Why are there even - indicators, since no lines were actually deleted. Only new lines were added. The lines with - are also present in the second range.
  2. Why are "text-a",, "text-b",, "text-c",, "text-x",, "text-y", and "text-z", in the diff, but not for example "text-unrelated-22",.
  3. The selection of lines in the diff seems arbitrary to me.
  4. What should @@ Commit message tell me?

More information

First, git show shows me, that both commits indeed intended to do the same change.

git show 1273567d876
             "text-c",
+            "text-added-in-the-commit-a",
+            "text-added-in-the-commit-b",
         ] as $key) {

git show 789a6775664
             "text-z",
+            "text-added-in-the-commit-a",
+            "text-added-in-the-commit-b",
         ] as $key) {

If I check out the commits under question, we see that both had to apply the changes to different starting situation, which is expected:

git checkout 1273567d876 && (show content of some/path/something.php: function initTexts())10

            […]
            "text-unrelated-6",
            "text-a",
            "text-b",
            "text-c",
            "text-added-in-the-commit-a",
            "text-added-in-the-commit-b",
        ] as $key) {
git checkout 789a6775664 && (show content of some/path/something.php: function initTexts())

            […]
            "text-unrelated-6",
            "text-a",
            "text-b",
            "text-c",
            "text-unrelated-7",
            […]
            "text-unrelated-22",
            "text-x",
            "text-y",
            "text-z",
            "text-added-in-the-commit-a",
            "text-added-in-the-commit-b",
        ] as $key) {

Thanks in advance!

Simon Lenz
  • 2,732
  • 5
  • 33
  • 39
  • Could be whitespace difference? Tab vs spaces. – KamilCuk Aug 04 '21 at 11:57
  • @KamilCuk I just checked and couldn't find a whitespace difference. – Simon Lenz Aug 04 '21 at 12:21
  • It's possible that `git range-diff` picked the wrong diffs to diff. (Though, looking again, I'm not sure that this explains what you're seeing. It does happen with range-diff sometimes, though.) I think in this case, what happened is that the range-diff code fed, to the diff engine, text that made the diff engine itself misfire and pick the wrong original sections. – torek Aug 04 '21 at 15:57
  • That is, as you noted: "we see that both had to apply the changes to different starting situation" - if you run the two `git diff`s one at a time, each picks a different start from which to generate a diff, but range-diff has fancy optimizations and may pick the *same* start both times by mistake. This makes it show the wrong diff-of-diffs. (Also, I have a vague memory of a recent bug report on the Git mailing list, of `git range-diff` having just this sort of problem, introduced in some particular recent-ish Git version during improvement of diffs in other tricky corner cases.) – torek Aug 04 '21 at 16:01

0 Answers0