Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git diff unique to merge commit

Say I have,

      A topic
     / \
D---E---F master

I can easily get the diff of D-E by doing

git diff D..E --name-status

and same for E-F, and E-A.

Commit F is a merge commit, and say it had a conflict. It was resolved by modifying foo.bar. foo.bar was git added, then the merge commit was committed. The merge conflict was resolved.

Now the change for foo.bar exists only in commit F. How do I get that diff?

Is there a way to get the diff of files that were uniquely introduced in a merge commit?

like image 669
Ken Hirakawa Avatar asked Jul 15 '11 22:07

Ken Hirakawa


People also ask

What is an alternative to merging in git?

If you would prefer a clean, linear history free of unnecessary merge commits, you should reach for git rebase instead of git merge when integrating changes from another branch.

Can I merge specific commit?

The git merge command is targeted at combining two branches. You can also use it for merging several commits into a single history. The merge commits involve two parent commits. Every time a new merge commit is made, git runs an automate merging of different histories.

Why you should rebase instead of merge?

Git rebase compresses all the changes into a single “patch.” Then it integrates the patch onto the target branch. Unlike merging, rebasing flattens history. It transfers the completed work from one branch to another. In the process, unwanted history is eliminated.

Can you cherry pick a merge?

With the cherry-pick command, Git lets you incorporate selected individual commits from any branch into your current Git HEAD branch. When performing a git merge or git rebase , all the commits from a branch are combined. The cherry-pick command allows you to select individual commits for integration.


1 Answers

git show on the merge commit will show changes not in any of its parents. For example:

$ echo 123 > file1.txt
$ git add file1.txt
$ git commit -am '123'

$ git checkout -b test
$ echo 1234 > file1.txt
$ git commit -am '1234'

$ git checkout HEAD~ -b test2
$ echo 0123 > file1.txt
$ git commit -am '0123'

$ git merge test
$ echo 01234 > file1.txt
$ git add file1.txt
$ git commit -am 'Merge test'

$ git show
commit f056a1c91d76c8dfce60a03122494dce92c1e161
Merge: 489f1d3 fcfd2bc
Date:   Fri Jul 15 20:30:17 2011 -0500

    Merge test

diff --cc file1.txt
index 40381e2,81c545e..3521a84
--- a/file1.txt
+++ b/file1.txt
@@@ -1,1 -1,1 +1,1 @@@
- 0123
 -1234
++01234
like image 53
dahlbyk Avatar answered Nov 13 '22 14:11

dahlbyk