如果您的存储库中存在带有尾随空格的现有提交,那么您将需要更改这些提交(重写历史记录),如果该存储库已被其他人推送和克隆,这可能会很痛苦。
但如果这是一个选项,那么您可以使用类似于gitolite 中的脚本:
#!/bin/bash
# from doener (who else!)
# to be called as an index-filter
if git rev-parse --quiet --verify $GIT_COMMIT^ >/dev/null
then
        against=$(map $(git rev-parse $GIT_COMMIT^))
        git reset -q $against -- .
else
        # Initial commit: diff against an empty tree object
        against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
        git rm --cached -rfq --ignore-unmatch '*'
fi
git diff --full-index $against $GIT_COMMIT | git apply --cached --whitespace=fix
像这样运行:
git filter-branch --index-filter '. ~/git-scripts/ws-fix.sh'
| 归档时间: | 
 | 
| 查看次数: | 1573 次 | 
| 最近记录: |