Purging file from Git repo failed, unable to create new backup

自古美人都是妖i 提交于 2019-11-27 05:02:26

问题


I tried to remove a file from my remote repo by running:

git filter-branch --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD

But Git complains that

Cannot create new backup. A previous backup already exists in refs/original/
Force overwriting the backup with -f
rm: cannot remove /.git-rewrite/backup-refs : Permission denied
rm: cannot remove directory /.git-rewrite : Directory not empty

This was after I already deleted the .git-rewrite directory on Windows.

How can I remove that file? It's a 29Mb file sitting on my repo, so I quite need to remove the file.

I tried to delete the commit in git rebase -i, but apparently because the commit touched a lot of different files, Git complains of conflicts and I aborted to be safe.


回答1:


You have already performed a filter-branch operation. After filter-branch, Git keeps refs to the old commits around, in case something goes wrong.

You can find those in .git/refs/original/…. Either delete that directory and all files within, or use the -f flag to force Git to delete the old references.

git filter-branch -f \
--index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD



回答2:


Use this command to remove original backup:

git update-ref -d refs/original/refs/heads/master

Here is gist I used to filter-branch my git repo: https://gist.github.com/k06a/25a0214c98bc19fd6817




回答3:


I had the same problem and the answer above didn't fix it. There was no .git/refs/original/ directory left. The solution for me was to delete the .git/packed-refs file.




回答4:


Add a force to the filter branch command.



来源:https://stackoverflow.com/questions/6403601/purging-file-from-git-repo-failed-unable-to-create-new-backup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!