threads / discuss / 39639

Visualizing merge conflicts after the fact (using kdiff3)

Subject: Visualizing merge conflicts after the fact (using kdiff3)

## tl;dr

9 messages between Jun 16, 2015 and Jul 6, 2015.

replies: 8people: 5as markdown or json

Eric Raible· Jun 16, 2015, 01:17 UTC · lore
I'm running 1.9.5.msysgit.1, but this is a general git question...

Upon returning from a vacation, I was looking at what people had been up to, and discovered on merge in which a colleague had resolved a merge incorrectly. It turns out that he has pushed *many* merges over the past year which had conflicts in my code, and now I don't trust any of them.

So naturally I want to check each of them for correctness.

I know about "git log -p -cc SHA -- path", but it really doesn't show just the conflicts so there's just too much noise in that output.

I use kdiff3 to resolve conflicts, so I'm looking for a way to visualize these already-resolved conflicts with that tool. As I said, there are many merges, so the prospect of checking out each sha, doing the merge, and then comparing the results is completely untenable.

Can anyone help? Surely other people have wanted to review how conflicts were resolved w/out looking at the noise of unconflicted changes, right?

Thanks - Eric (raible at gmail )
Johannes Schindelin· Jun 16, 2015, 09:43 UTC · re: Eric Raible · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Hi Eric,
On 2015-06-16 03:17, Eric Raible wrote:
Show 21 quoted lines
> I'm running 1.9.5.msysgit.1, but this is a general git question...
> 
> Upon returning from a vacation, I was looking at what people had been
> up to, and discovered on merge in which a colleague had resolved a merge
> incorrectly.  It turns out that he has pushed *many* merges over the past
> year which had conflicts in my code, and now I don't trust any of them.
> 
> So naturally I want to check each of them for correctness.
> 
> I know about "git log -p -cc SHA -- path", but it really doesn't
> show just the conflicts so there's just too much noise in that output.
> 
> I use kdiff3 to resolve conflicts, so I'm looking for a way to
> visualize these already-resolved conflicts with that tool.
> As I said, there are many merges, so the prospect of checking
> out each sha, doing the merge, and then comparing the results
> is completely untenable.
> 
> Can anyone help?  Surely other people have wanted to review how
> conflicts were resolved w/out looking at the noise of unconflicted
> changes, right?
If I was walking in your shoes, I would essentially recreate the merge conflicts and then use "git diff <merge-commit>" with the resolved merge in your current history.
Something like this:

```bash mergecommit=$1

# probably should verify that the working directory is clean, yadda yadda

# recreate merge conflicts on an unnamed branch (Git speak: detached HEAD) git checkout $mergecommit^ git merge $mergecommit^2 || die "This merge did not have any problem!"

# compare to the actual resolution as per the merge commit git diff $mergecommit ```

To list all the merge commits in the current branch, I would use the command-line:

```bash git rev-list --author="My Colleague" --parents HEAD | sed -n 's/ .* .*//p' ```

(i.e. listing all the commits with their parents, then filtering just the ones having more than one parent, which would include octopus merges if your history has them.)
Hopefully this gives you good ideas how to proceed.

Ciao, Johannes

Eric Raible· Jun 16, 2015, 20:17 UTC · re: Johannes Schindelin · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

On 6/16/2015 2:43 AM, Johannes Schindelin wrote:
Show 57 quoted lines
> Hi Eric,
> 
> On 2015-06-16 03:17, Eric Raible wrote:
>> I'm running 1.9.5.msysgit.1, but this is a general git question...
>>
>> Upon returning from a vacation, I was looking at what people had been
>> up to, and discovered on merge in which a colleague had resolved a merge
>> incorrectly.  It turns out that he has pushed *many* merges over the past
>> year which had conflicts in my code, and now I don't trust any of them.
>>
>> So naturally I want to check each of them for correctness.
>>
>> I know about "git log -p -cc SHA -- path", but it really doesn't
>> show just the conflicts so there's just too much noise in that output.
>>
>> I use kdiff3 to resolve conflicts, so I'm looking for a way to
>> visualize these already-resolved conflicts with that tool.
>> As I said, there are many merges, so the prospect of checking
>> out each sha, doing the merge, and then comparing the results
>> is completely untenable.
>>
>> Can anyone help?  Surely other people have wanted to review how
>> conflicts were resolved w/out looking at the noise of unconflicted
>> changes, right?
> 
> If I was walking in your shoes, I would essentially recreate the merge conflicts and then use "git diff <merge-commit>" with the resolved merge in your current history.
> 
> Something like this:
> 
> ```bash
> mergecommit=$1
> 
> # probably should verify that the working directory is clean, yadda yadda
> 
> # recreate merge conflicts on an unnamed branch (Git speak: detached HEAD)
> git checkout $mergecommit^
> git merge $mergecommit^2 ||
> die "This merge did not have any problem!"
> 
> # compare to the actual resolution as per the merge commit
> git diff $mergecommit
> ```
> 
> To list all the merge commits in the current branch, I would use the command-line:
> 
> ```bash
> git rev-list --author="My Colleague" --parents HEAD |
> sed -n 's/ .* .*//p'
> ```
> 
> (i.e. listing all the commits with their parents, then filtering just the ones having more than one parent, which would include octopus merges if your history has them.)
> 
> Hopefully this gives you good ideas how to proceed.
> 
> Ciao,
> Johannes
> .
Thanks for the reply, Johannes.

That basically the procedure that I did on just the one I stumbled across. But what I really want is just a way to review how each conflicts was resolved w/out having to re-resolve each one myself.

gitk (obviously) makes it trivial to view changes in normal commits, but given that git provides such a straightforward conflict resolution model I'm surprised that there isn't a corresponding straightforward way of viewing those resolved conflicts in context.

Thanks - Eric
Michael J Gruber· Jun 18, 2015, 12:26 UTC · re: Johannes Schindelin · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Johannes Schindelin venit, vidit, dixit 16.06.2015 11:43:
Show 42 quoted lines
> Hi Eric,
> 
> On 2015-06-16 03:17, Eric Raible wrote:
>> I'm running 1.9.5.msysgit.1, but this is a general git question...
>>
>> Upon returning from a vacation, I was looking at what people had been
>> up to, and discovered on merge in which a colleague had resolved a merge
>> incorrectly.  It turns out that he has pushed *many* merges over the past
>> year which had conflicts in my code, and now I don't trust any of them.
>>
>> So naturally I want to check each of them for correctness.
>>
>> I know about "git log -p -cc SHA -- path", but it really doesn't
>> show just the conflicts so there's just too much noise in that output.
>>
>> I use kdiff3 to resolve conflicts, so I'm looking for a way to
>> visualize these already-resolved conflicts with that tool.
>> As I said, there are many merges, so the prospect of checking
>> out each sha, doing the merge, and then comparing the results
>> is completely untenable.
>>
>> Can anyone help?  Surely other people have wanted to review how
>> conflicts were resolved w/out looking at the noise of unconflicted
>> changes, right?
> 
> If I was walking in your shoes, I would essentially recreate the merge conflicts and then use "git diff <merge-commit>" with the resolved merge in your current history.
> 
> Something like this:
> 
> ```bash
> mergecommit=$1
> 
> # probably should verify that the working directory is clean, yadda yadda
> 
> # recreate merge conflicts on an unnamed branch (Git speak: detached HEAD)
> git checkout $mergecommit^
> git merge $mergecommit^2 ||
> die "This merge did not have any problem!"
> 
> # compare to the actual resolution as per the merge commit
> git diff $mergecommit
> ```

This type of request comes up often (for a reason). I'm wondering whether we could support it more systematically, either by exposing the steps above as a command, or by storing the unresolved merge somewhere (leveraging stash or rerere).

Show 8 quoted lines
> To list all the merge commits in the current branch, I would use the command-line:
> 
> ```bash
> git rev-list --author="My Colleague" --parents HEAD |
> sed -n 's/ .* .*//p'
> ```
> 
> (i.e. listing all the commits with their parents, then filtering just the ones having more than one parent, which would include octopus merges if your history has them.)
:)
"--merges" (aka "--min-parents=2") is your friend here.
Show 6 quoted lines
> 
> Hopefully this gives you good ideas how to proceed.
> 
> Ciao,
> Johannes
> 
Michael
Johannes Schindelin· Jun 18, 2015, 13:05 UTC · re: Michael J Gruber · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Hi Micha,
On 2015-06-18 14:26, Michael J Gruber wrote:
Show 14 quoted lines
> Johannes Schindelin venit, vidit, dixit 16.06.2015 11:43:
>
>> To list all the merge commits in the current branch, I would use the command-line:
>>
>> ```bash
>> git rev-list --author="My Colleague" --parents HEAD |
>> sed -n 's/ .* .*//p'
>> ```
>>
>> (i.e. listing all the commits with their parents, then filtering just the ones having more than one parent, which would include octopus merges if your history has them.)
> 
> :)
> 
> "--merges" (aka "--min-parents=2") is your friend here.
Learnt something!

Thanks, Dscho

Junio C Hamano· Jun 18, 2015, 15:57 UTC · re: Michael J Gruber · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Michael J Gruber <git@drmicha.warpmail.net> writes:
> This type of request comes up often (for a reason). I'm wondering
> whether we could support it more systematically, either by exposing the
> steps above as a command, or by storing the unresolved merge somewhere
> (leveraging stash or rerere).
Perhaps 'tr/remerge-diff' (on 'pu') is of interest?
Michael J Gruber· Jun 19, 2015, 08:34 UTC · re: Junio C Hamano · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Junio C Hamano venit, vidit, dixit 18.06.2015 17:57:
Show 9 quoted lines
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> This type of request comes up often (for a reason). I'm wondering
>> whether we could support it more systematically, either by exposing the
>> steps above as a command, or by storing the unresolved merge somewhere
>> (leveraging stash or rerere).
> 
> Perhaps 'tr/remerge-diff' (on 'pu') is of interest?
> 
Ingenious!

To me, this seems to be the most useful view if you want to understand a merge just from the parents and the merge commit. Since you would use that for individual commits only, the cpu cycles are well spent.

As and added benefit, tr/remerge-diff merges to current next with conflicts (oid...) so that you get to test it on its own merge!

I haven't reviewed remerge-diff but merged it on top of my own local additions and ran the full test suite successfully. Any big blocker to watch out for?

Michael
Junio C Hamano· Jun 19, 2015, 16:19 UTC · re: Michael J Gruber · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

Michael J Gruber <git@drmicha.warpmail.net> writes:
Show 7 quoted lines
> Junio C Hamano venit, vidit, dixit 18.06.2015 17:57:
>> 
>> Perhaps 'tr/remerge-diff' (on 'pu') is of interest?
>
> I haven't reviewed remerge-diff but merged it on top of my own local
> additions and ran the full test suite successfully. Any big blocker to
> watch out for?

"What's cooking" report marks it as "Waiting for a reroll. ($gmane/256591)."

So 
  http://thread.gmane.org/gmane.comp.version-control.git/256591
would be the first place to revisit.
Sebastian Schuberth· Jul 6, 2015, 19:38 UTC · re: Eric Raible · lore

Re: Visualizing merge conflicts after the fact (using kdiff3)

On 16.06.2015 03:17, Eric Raible wrote:
> So naturally I want to check each of them for correctness.
Sorry for joining this thread so late, I only come to know about it from the draft of the upcoming Git Rev News 5 [1].
A while ago Robin Green was asking a very similar question on StackOverflow [2], and I came up with a script called "git-show-merge-resolution.sh" [3]. Maybe that's something you're interested in, too.

[1] https://github.com/git/git.github.io/blob/master/rev_news/drafts/edition-5.md#support [2] stackoverflow.com/questions/24958182/kdiff3-to-code-review-merge-commit/24958228 [3] https://github.com/sschuberth/dev-scripts/blob/master/git/git-show-merge-resolution.sh

-- 
Sebastian Schuberth

← back to recent threads