我怎样才能找到空的git提交?

时间:2014-10-31 21:40:59

标签: git git-filter-branch

我可以使用哪些命令在git存储库中查找空提交,即git filter-branch --prune-empty将删除的提交?

2 个答案:

答案 0 :(得分:9)

您希望排除无父提交和合并提交,然后查看哪些提交与其父级具有相同的树。

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

答案 1 :(得分:3)

作为第一个近似,以相反的顺序列出所有提交,并记录任何具有与之前相同的树形哈希的行:

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

您可以通过忽略具有多个父项的任何提交并确认记录的行实际上是之前的行的子项来改进此。

相关问题