我不小心将一些大型测试wav文件提交到了我的代码库,它们占用了我Github账户很多空间。我该如何从历史记录中删除这些文件?
注意:这些文件是一段时间前提交的,不在HEAD提交中。
如果没有修改历史记录,就无法删除它们,因此如果有人拉取了这些更改,您可能需要处理混乱的情况 - 请参见 从上游恢复 在 man git-rebase
中的变基。根据您的工作流程,这可能相当糟糕 - 无论如何,您可能需要让每个人都意识到他们需要切换到“新”的主分支,并在其上重新设置正在进行的任何工作。
如果提交仍然在最新状态,您可以重置为之前的提交:
git reset --hard HEAD^
git rm test.wav
git commit --amend
git rebase -i <commit-before-mistake>
git push -f origin
git filter-branch --index-filter ’git rm --cached --ignore-unmatch filename’ HEAD
git commit --amend
if it is your HEAD commit; another is git rebase --interactive
.Force push the updated branch to github.
git push --force github
(where github
is the name of your remote for GitHub).
这将从活动历史中删除它。要实际回收空间,GitHub需要进行垃圾回收。如果他们不自动执行此操作,则我不确定是否有明确的方法来执行此操作。您可能需要提交支持请求。