Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find empty git commits?

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?

like image 537
Eugene Yarmash Avatar asked Oct 31 '14 21:10

Eugene Yarmash


1 Answers

You'd want to exclude parentless commits and merge commits, then see which ones have the same tree as their parent.

for sha in $(git rev-list --min-parents=1 --max-parents=1 --all)
do
   if [ $(git rev-parse ${sha}^{tree}) == $(git rev-parse ${sha}^1^{tree} ) ]
   then
       echo "${sha} will be pruned"
   fi
done
like image 134
Andrew C Avatar answered Oct 13 '22 22:10

Andrew C