git删除某个文件的提交记录

发现不小心提交了包含密码的文件,所以记录下删除该文件及记录的方法

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/main/resources/application.properties' --prune-empty --tag-name-filter cat -- --all

src/main/resources/application.properties为该文件,替换成需要的文件即可。

如果提示:Cannot rewrite branches: Your index contains uncommitted changes.

则需要:

git stash

最后提交到git:

git push origin --force --all