Alexander Bird
Alexander Bird

Reputation: 40639

diff _both_ parents of git commit at once

Isn't there a way to view the diff of a merge commit in such a way that you see the diff between the two parents at once?

I'm not talking about viewing the diff with parent 1, and then you see the diff with parent 2. The output I am wanting has two columns used on the left. For every line which differs from parent one, column one has a +/- sign. And likewise for parent two.

It would look like this:

   Hello
 - World
-- How are you
+  doing?

In this output, any line which starts with two pluses or minuses means that the merge commit itself introduced the change apart from an automerge.

Can you do this in git?

EDIT:

Here is a related question: How do you see / show a git merge conflict resolution that was done, given a merge commit SHA1?

My use case is the same as that question: I want to see the changes made as a result of resolving merge conflicts.

Upvotes: 2

Views: 400

Answers (2)

Michael come lately
Michael come lately

Reputation: 9333

You are looking for the combined diff format. It's coincidentally the default format for git show as you discovered, but you can get it on any command with diff output. Documentation excerpt below:

Combined diff format

Any diff-generating command can take the -c or --cc option to produce a combined diff when showing a merge. This is the default format when showing merges with git-diff[1] or git-show[1]. Note also that you can give suitable --diff-merges option to any of these commands to force generation of diffs in specific format.

A "combined diff" format looks like this:

diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
        return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
  }

- static void describe(char *arg)
 -static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
  {
 +      unsigned char sha1[20];
 +      struct commit *cmit;
        struct commit_list *list;
        static int initialized = 0;
        struct commit_name *n;

 +      if (get_sha1(arg, sha1) < 0)
 +              usage(describe_usage);
 +      cmit = lookup_commit_reference(sha1);
 +      if (!cmit)
 +              usage(describe_usage);
 +
        if (!initialized) {
                initialized = 1;
                for_each_ref(get_name);

Upvotes: 1

Alexander Bird
Alexander Bird

Reputation: 40639

git show seems to do what I want.

In the test git repo I made: https://github.com/Thr4wn/test , here is the output of git show:

$ git show master
commit 5bb48fc7481f973cee9a4441d3466fe513bcd685
Merge: 190fded f678b58
Author: Alexander Bird <[email protected]>
Date:   Wed Jun 3 15:30:03 2015 -0400

    merged

diff --cc README
index 94954ab,ce01362..363f0a5
--- a/README
+++ b/README
@@@ -1,2 -1,1 +1,3 @@@
  hello
++there
 +world

This is what I was remembering existed somehow.

However, git show (with no -m flag) only shows the changes that are different from both parents. In my case, that's all I'm after. If there are no merge conflicts, then git show will probably have no diff.

Upvotes: 2

Related Questions