2

In one branch, I added a line of text. In another branch, I modified some lines. I then merged these together, and when fixing the merge conflicts, kept only the changes from the second branch. My question is: Why does removing the line added in 16fcbc7 not appear in the merge commit's diff?

Here is the output of git log --oneline --graph -p. The (empty) diff is the same thing shown for git show 584d05b.

*   584d05b (HEAD, origin/capitalize-lenore) Merge branch 'master' into capitalize-lenore
|\  
| * 16fcbc7 (origin/master) Improve the poem
| | diff --git a/the-raven.txt b/the-raven.txt
| | index adcd9a1..a74559b 100644
| | --- a/the-raven.txt
| | +++ b/the-raven.txt
| | @@ -29,6 +29,7 @@ Darkness there, and nothing more.
| |  Deep into that darkness peering, long I stood there wondering, fearing,
| |  Doubting, dreaming dreams no mortal ever dared to dream before;
| |  But the silence was unbroken, and the darkness gave no token,
| | +and it all was left unspoken, in the vastness of the ocean,
| |  And the only word there spoken was the whispered word, "Lenore!"
| |  This I whispered, and an echo murmured back the word, "Lenore!"
| |  Merely this and nothing more.
* | 6c0160b Capitalize LENORE
|/  
|   diff --git a/the-raven.txt b/the-raven.txt
|   index adcd9a1..a9f39d6 100644
|   --- a/the-raven.txt
|   +++ b/the-raven.txt
|   @@ -8,8 +8,8 @@ Only this, and nothing more."
|    Ah, distinctly I remember it was in the bleak December,
|    And each separate dying ember wrought its ghost upon the floor.
|    Eagerly I wished the morrow:—vainly I had sought to borrow
|   -From my books surcease of sorrow—sorrow for the lost Lenore—
|   -For the rare and radiant maiden whom the angels name Lenore—
|   +From my books surcease of sorrow—sorrow for the lost LENORE—
|   +For the rare and radiant maiden whom the angels name LENORE—
|    Nameless here for evermore.
|    
|    And the silken sad uncertain rustling of each purple curtain
|   @@ -29,8 +29,8 @@ Darkness there, and nothing more.
|    Deep into that darkness peering, long I stood there wondering, fearing,
|    Doubting, dreaming dreams no mortal ever dared to dream before;
|    But the silence was unbroken, and the darkness gave no token,
|   -And the only word there spoken was the whispered word, "Lenore!"
|   -This I whispered, and an echo murmured back the word, "Lenore!"
|   +And the only word there spoken was the whispered word, "LENORE!"
|   +This I whispered, and an echo murmured back the word, "LENORE!"
|    Merely this and nothing more.
|    
|    Back into the chamber turning, all my soul within me burning,
|   @@ -92,8 +92,8 @@ She shall press, ah, nevermore!
|    Then, methought, the air grew denser, perfumed from an unseen censer
|    Swung by seraphim whose foot-falls tinkled on the tufted floor.
|    "Wretch," I cried, "thy God hath lent thee—by these angels he hath sent thee
|   -Respite—respite and nepenthe from thy memories of Lenore!
|   -Quaff, oh quaff this kind nepenthe, and forget this lost Lenore!"
|   +Respite—respite and nepenthe from thy memories of LENORE!
|   +Quaff, oh quaff this kind nepenthe, and forget this lost LENORE!"
|    Quoth the Raven, "Nevermore."
|    
|    "Prophet!" said I, "thing of evil!—prophet still, if bird or devil!—
|   @@ -106,8 +106,8 @@ Quoth the Raven, "Nevermore."
|    "Prophet!" said I, "thing of evil—prophet still, if bird or devil!
|    By that Heaven that bends above, us—by that God we both adore—
|    Tell this soul with sorrow laden if, within the distant Aidenn,
|   -It shall clasp a sainted maiden whom the angels name Lenore—
|   -Clasp a rare and radiant maiden whom the angels name Lenore."
|   +It shall clasp a sainted maiden whom the angels name LENORE—
|   +Clasp a rare and radiant maiden whom the angels name LENORE."
|    Quoth the Raven, "Nevermore."
|    
|    "Be that word our sign of parting, bird or fiend!" I shrieked, upstarting—
* 3c0e072 Add newlines
.
.
.

This question refers to commits in this repository.

dta
  • 654
  • 4
  • 19
  • 1
    I think it shows nothing because there are no differences when comparing with what you have as the _first parent_ of the merge revision. – eftshift0 Sep 09 '20 at 15:52
  • If I change the order of the parents, the new commit still shows the same (lack of) diff. – dta Sep 09 '20 at 18:16
  • Does this answer your question? [git show of a merge commit](https://stackoverflow.com/questions/40986518/git-show-of-a-merge-commit) – LeGEC Sep 09 '20 at 20:50
  • No, that does not answer my question. I want to know why nothing shows up in the combined diff for this merge commit. According to the answer in that question there should be a combined diff since both parents modified the same file. – dta Sep 09 '20 at 22:34

1 Answers1

2

By default : git log -p does not display any kind of diff for a merge commit.

You can add options to modify that :

  • --cc to get the combined diff format
  • -m to get the full diff format

or explicitly check the diff with either of its parent :

git diff HEAD^ HEAD  # you will see the differences brought in by the second parent
git diff HEAD^2 HEAD # you will see the differences brought in by the first parent
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • `-m` shows all diffs from each parent separately. `-c` shows combined diffs in files that have changes from both parents, `--cc` shows only the hunks where both parents differ from the result, i.e. where it looks like some sort of conflict resolution happened that was more than just ours or theirs. You can widen out `--cc`'s view of potential conflicts with e.g. `-U10` to show changes accepted from different parents within ten lines of each other. – jthill Sep 09 '20 at 22:22
  • `git log --cc -p` shows no diff for this merge commit. `git log -c -p` also shows no diff. `git log -m -p` does show a full diff, but I'm hoping to be able to show just the parts of the diff were merge conflicts were resolved. A diff with a specific parent doesn't help because I'm interested in the sections where there were merge conflicts – dta Sep 09 '20 at 22:23
  • @jthill Is there a way to get something like `--cc`, but also including conflict resolution that was just ours or theirs? – dta Sep 09 '20 at 22:26
  • Yes, but that's not just diffing, which compares against the work tree, that's diffing against the actual merge base. i.e. rerunning the merge. The hands-down quickest way to do that is a minimum-checkout merge in a scratch clone, lemme hunt down a ref for that – jthill Sep 09 '20 at 22:29
  • The basic recipe is `git clone -ns . $(mktemp -d); cd $_; git reset -q $merge^1; git merge $merge^2`, if you then diff against the actual merge result you'll see all conflict resolutions. – jthill Sep 09 '20 at 22:34
  • If we have 3 files, is it not easy to get a 3-way diff between those files? – dta Sep 09 '20 at 22:35
  • Not at all difficult, and that's what diff --cc does, but a three-way diff between an ours- or theirs- resolution and the two tips shows only one change. What you're after is diffing the tips against the base to find the change hunks and then diffing those against the eventual result. That's four potentially-different versions of each hunk. It takes some doing. Not all that much, but some. – jthill Sep 09 '20 at 23:17