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

标签 git git-commit git-filter-branch git-rewrite-history

我试图通过运行从我的远程仓库中删除一个文件:

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

但是 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

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

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

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

最佳答案

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

您可以在 .git/refs/original/... 中找到它们。要么删除该目录及其中的所有文件,要么使用 -f 标志强制 Git 删除旧引用。

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

关于git - 从 Git 存储库中清除文件失败,无法创建新备份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6403601/

相关文章:

git - 错误 : cannot update the ref <branch>: unable to append to <git location>: Not a directory

Android 源代码、Git/Repo 和错误 : '.../.repo/repo/.git/clone.bundle' does not look like a v2 bundle file

git - 如何在终端中确认 `git commit --amend` 之后的更改?

git - 在 git 中强制推送个人分支是否安全?

使用 git filter-branch 然后 git push --force 清除大文件后,远程(Gitlab)上的 Git 存储库大小仍然很大

git - 删除 git repo 中所有以前版本的文件

linux - 如何使用 git 提取提交者的电子邮件?

linux - 如何更新提示符以显示 Linux 上当前的 git 分支?

GITLAB Web IDE更改默认选项-创建新分支

git - 删除既不在子树中也不在原始存储库中的提交