Git仓库删除文件记录无脑使用方法
方法一:filter-branch
执行
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch <path-to-your-remove-file>" --prune-empty --tag-name-filter cat -- --all
即可删除[1]。
注:
<path-to-your-remove-file>
替换为要删除的文件,可以使用通配符;- Linux里可以使用单引号,但是Windows里只能用双引号[2];
将修改后的提交推送到远端:
git push origin master --force --all
git push origin master --force --tags
清理、回收空间:
git gc --aggressive --prune=now
参考
- Git如何永久删除文件(包括历史记录) - shines77 - 博客园;
- Removing files from git history - bad revision error - Stack Overflow;
方法二:filter-repo
没试过