Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
909 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...