从 Git 存储库清除文件失败,无法创建新备份
我尝试通过运行以下命令从远程存储库中删除文件:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD
但 Git 抱怨说
无法创建新备份。先前的备份已存在于 refs/original/
使用 -f 强制覆盖备份
rm:无法删除 /.git-rewrite/backup-refs :权限被拒绝
rm:无法删除目录 /.git-rewrite :目录不为空
这是在我已经删除了 Windows 上的 .git-rewrite 目录之后。
我怎样才能删除该文件?这是一个 29Mb 的文件,位于我的存储库中,因此我非常需要删除该文件。
我尝试删除 git rebase -i 中的提交,但显然因为该提交触及了很多不同的文件,Git 抱怨存在冲突,为了安全起见,我中止了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您已经执行了过滤分支操作。在过滤分支之后,Git 会保留对旧提交的引用,以防出现问题。
您可以在
.git/refs/original/...
中找到它们。删除该目录及其中的所有文件,或者使用-f
标志强制 Git 删除旧引用。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 存储库的要点: https:// gist.github.com/k06a/25a0214c98bc19fd6817
Use this command to remove original backup:
Here is gist I used to filter-branch my git repo: https://gist.github.com/k06a/25a0214c98bc19fd6817
我遇到了同样的问题,上面的答案没有解决它。没有留下 .git/refs/original/ 目录。我的解决方案是删除 .git/packed-refs 文件。
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.
为过滤器分支命令添加强制。
Add a force to the filter branch command.