从 Git 存储库清除文件失败,无法创建新备份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6403601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:12:48  来源:igfitidea点击:

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

gitgit-commitgit-filter-branchgit-rewrite-history

提问by Cardin Lee JH

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

但是 Git 抱怨说

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

无法创建新备份。以前的备份已存在于 refs/original/
用 -f
rm强制覆盖备份:无法删除 /.git-rewrite/backup-refs:权限被拒绝
rm:无法删除目录 /.git-rewrite:目录不为空

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

这是在我已经删除了 Windows 上的 .git-rewrite 目录之后。

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

我怎样才能删除那个文件?这是一个 29Mb 的文件,位于我的存储库中,因此我非常需要删除该文件。

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.

我试图删除 中的提交git rebase -i,但显然因为提交涉及了很多不同的文件,Git 抱怨冲突,为了安全起见,我中止了。

回答by knittl

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

您已经执行了过滤器分支操作。在过滤分支之后,Git 保留对旧提交的引用,以防出现问题。

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

你可以在.git/refs/original/…. 删除该目录和其中的所有文件,或使用该-f标志强制 Git 删除旧引用。

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

回答by k06a

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

这是我用来过滤分支我的 git repo 的要点:https: //gist.github.com/k06a/25a0214c98bc19fd6817

回答by Yaron

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.

我遇到了同样的问题,上面的答案没有解决。没有 .git/refs/original/ 目录了。我的解决方案是删除 .git/packed-refs 文件。

回答by Adam Dymitruk

Add a force to the filter branch command.

向过滤器分支命令添加强制。