git 删除指定文件的历史记录

2023-11-18 15:20:03 浏览数 (1)

  1. 删除文件 src/file-to-delete.txt 替换为要删除的文件路径
代码语言:javascript复制
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/file-to-delete.txt' --prune-empty --tag-name-filter cat -- --all

控制台输出,已经完成删除

WARNING: git-filter-branch has a glut of gotchas generating mangled history rewrites. Hit Ctrl-C before proceeding to abort, then use an alternative filtering tool such as ‘git filter-repo’ (https://github.com/newren/git-filter-repo/) instead. See the filter-branch manual page for more details; to squelch this warning, set FILTER_BRANCH_SQUELCH_WARNING=1. Proceeding with filter-branch… Rewrite 0bc18b0f71780c02baa7529968017c898847fae2 (47/117) (8 seconds passed, remaining 11 predicted) rm ‘src/file-to-delete.txt’ … … Ref ‘refs/heads/master’ was rewritten Ref ‘refs/remotes/origin/master’ was rewritten WARNING: Ref ‘refs/remotes/origin/master’ is unchanged

  1. 强制推送覆盖远端库 git push origin --force master

参考 https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository#purging-a-file-from-your-repositorys-history https://rtyley.github.io/bfg-repo-cleaner/

0 人点赞