How can I find empty git commits?

后端 未结 2 480
清酒与你
清酒与你 2021-01-12 06:11

What command(s) can I use to find empty commits in a git repository, i.e. the commits that would be removed by git filter-branch --prune-empty?

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 06:51

    As a first approximation, list all commits in reverse order and log any line that has the same tree hash as the one before:

    git log --all --reverse --format='%H %t' | while read h t; do
      if [ "$lt" = "$t" ]; then
        echo "$h"
      fi
      lt="$t"
    done
    

    You could improve this by ignoring any commit with multiple parents and confirming that the logged line is actually a child of the one before.

提交回复
热议问题