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

前端 未结 11 636
旧时难觅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: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  --oneline
    git range diff  --reverse -p
    git range diff  --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.

提交回复
热议问题