我如何找到空的git提交?
答
你想要排除父母提交和合并提交,然后看哪些人有与他们的父母相同的树。
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
答
作为第一个近似值,单子所有的提交和日志具有相同的树哈希作为一个之前的任何行:
git log --all --reverse --format='%H %t' | while read h t; do
if [ "$lt" = "$t" ]; then
echo "$h"
fi
lt="$t"
done
你可以忽略任何与多个父提交和确认改善这种该日志行实际上是之前的一个孩子。