這是一個可以修改提交歷史的命令,威力很猛的后悔葯。
1、徹底刪除不需要的文件
比如一不小心把 node_modules 目錄加入git倉庫了,導致倉庫很大 :
git filter-branch -f --prune-empty --index-filter "git rm --cached --ignore-unmatch -fr ./node_modules" -- --all
2、修改提交用戶名
git filter-branch -f --env-filter "GIT_AUTHOR_NAME=fwindpeak" -- --all
3、修改提交郵箱
git filter-branch -f --env-filter "GIT_AUTHOR_EMAIL=fwindpeak@xxx.com" -- --all
注意,如果在windows下操作,必須用雙引號。
其他更詳細的操作,參考這里: https://git-scm.com/docs/git-filter-branch