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

前端 未结 11 578
旧时难觅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:28

    Seems like answered here: https://public-inbox.org/git/7vd392ezhx.fsf@alter.siamese.dyndns.org/

    So in a similar way, running

    $ git diff --cc $M $M^1 $M^2 $(git merge-base $M^1 $M^2)

    should show a combined patch that explains the state at $M relative to the states recorded in its parents and the merge base.

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

    I built a general-purpose approach to doing various operations on a merge's commits.

    Step One: Add an alias to git by editing ~/.gitconfig:

    [alias]
      range = "!. ~/.githelpers && run_on_merge_range"
    

    Step Two: In ~/.githelpers, define a bash function:

    run_on_merge_range() {
      cmd=$1; shift
      commit=$1; shift
      range=$(git show $commit | grep Merge: | awk '{print $2 "..." $3}')
      echo "git $cmd $range $@"
      if [ -z $range ]; then
        echo "No merge detected"
        exit 1
      fi
      git $cmd $range $@
    }
    

    Step Three: Profit!

    git range log <merge SHA> --oneline
    git range diff <merge SHA> --reverse -p
    git range diff <merge SHA> --name-only
    

    There is probably a LOT of room for improvement here, I just whipped this together to get past an annoying situation. Feel free to mock my bash syntax and/or logic.

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

    in your case you just need to

    git diff HEAD^ HEAD^2
    

    or just hash for you commit:

    git diff 0e1329e55^ 0e1329e55^2
    
    0 讨论(0)
  • 2020-11-28 01:42

    You can create branch with HEAD set to one commit before merge. Then, you can do:

    git merge --squash testing
    

    This will merge, but not commit. Then:

    git diff
    
    0 讨论(0)
  • 2020-11-28 01:45

    If your merge commit is commit 0e1329e5, as above, you can get the diff that was contained in this merge by:

    git diff 0e1329e5^..0e1329e5
    

    I hope this helps!

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

    If you are sitting at the merge commit then this shows the diffs:

    git diff HEAD~1..HEAD

    If you're not at the merge commit then just replace HEAD with the merge commit. This method seems like the simplest and most intuitive.

    0 讨论(0)
提交回复
热议问题