How to “git show” a merge commit with combined diff output even when every changed file agrees with one of the parents?

前端 未结 11 579
旧时难觅i
旧时难觅i 2020-11-28 01:15

After doing a \"simple\" merge (one without conflicts), git show usually only shows something like

commit 0e1329e551a5700614a2a34d8101e92fd9f2ca         


        
相关标签:
11条回答
  • 2020-11-28 01:46

    No, there is no way to do this with git show. But it would certainly be nice sometimes, and it would probably be relatively easy to implement in the git source code (after all, you just have to tell it to not trim out what it thinks is extraneous output), so the patch to do so would probably be accepted by the git maintainers.

    Be careful what you wish for, though; merging a branch with a one-line change that was forked three months ago will still have a huge diff versus the mainline, and so such a full diff would be almost completely unhelpful. That's why git doesn't show it.

    0 讨论(0)
  • 2020-11-28 01:46

    I think you just need 'git show -c $ref'. Trying this on the git repository on a8e4a59 shows a combined diff (plus/minus chars in one of 2 columns). As the git-show manual mentions, it pretty much delegates to 'git diff-tree' so those options look useful.

    0 讨论(0)
  • 2020-11-28 01:50

    You can use the diff-tree command with the -c flag. This command shows you what files have changed in the merge commit.

    git diff-tree -c {merged_commit_sha}
    

    I got the -c flag's description from Git-Scm:

    This flag changes the way a merge commit is displayed (which means it is useful only when the command is given one , or --stdin). It shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time (which is what the -m option does). Furthermore, it lists only files which were modified from all parents.

    0 讨论(0)
  • 2020-11-28 01:51

    Look at the commit message:

    commit 0e1329e551a5700614a2a34d8101e92fd9f2cad6 (HEAD, master)
    Merge: fc17405 ee2de56
    Author: Tilman Vogel <email@email>
    Date:   Tue Feb 22 00:27:17 2011 +0100
    
    Merge branch 'testing' into master
    

    notice the line:

    Merge: fc17405 ee2de56
    

    take those two commit ids and reverse them. so in order get the diff that you want, you would do:

    git diff ee2de56..fc17405
    

    to show just the names of the changed files:

    git diff --name-only ee2de56..fc17405
    

    and to extract them, you can add this to your gitconfig:

    exportfiles = !sh -c 'git diff $0 --name-only | "while read files; do mkdir -p \"$1/$(dirname $files)\"; cp -vf $files $1/$(dirname $files); done"'
    

    then use it by doing:

    git exportfiles ee2de56..fc17405 /c/temp/myproject
    
    0 讨论(0)
  • 2020-11-28 01:53

    A better solution (mentioned by @KrisNuttycombe):

    git diff fc17405...ee2de56
    

    for the merge commit:

    commit 0e1329e551a5700614a2a34d8101e92fd9f2cad6 (HEAD, master)
    Merge: fc17405 ee2de56
    Author: Tilman Vogel <email@email>
    Date:   Tue Feb 22 00:27:17 2011 +0100
    

    to show all of the changes on ee2de56 that are reachable from commits on fc17405. Note the order of the commit hashes - it's the same as shown in the merge info: Merge: fc17405 ee2de56

    Also note the 3 dots ... instead of two!

    For a list of changed files, you can use:

    git diff fc17405...ee2de56 --name-only
    
    0 讨论(0)
提交回复
热议问题