从git-git命令中删除历史记录失败

时间:2013-09-11 16:30:51

标签: git github purge

我试图从Git历史中清除项目bin目录。我已经将'bin'添加到.gitignore并成功运行$git rm --cached -r bin。现在我尝试使用GitHub帮助页面中建议的命令来清除历史记录:

$ git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch bin' \
  --prune-empty --tag-name-filter cat -- --all

但这会导致错误:

Rewrite <hash> (1/164) fatal: not removing 'bin' recursively without -r
index filter failed: git rm --cached --ignore-unmatch bin
rm: cannot remove 'c:/pathToMyLocalRepo/.git-rewrite/revs': Permission denied
rm: cannot remove directory 'c:/pathToMyLocalRepo/.git-rewrite': Directory not empty

没有其他程序持有/转开。 / rev在指定的路径中不存在,.git-rewrite 为空。

我不确定我应该在哪里添加-r? 否则命令不正确?

我当然需要将bin本身保存在本地本地回购中,因为这是我的工作目录。

由于

2 个答案:

答案 0 :(得分:4)

好的,所以我需要做的就是将-r添加到rm命令部分(如下所示)。我猜测这是因为bin是一个目录而不是一个文件,因此必须以递归方式删除,否则它包含的文件(或有关它们的信息)将被孤立

$ git filter-branch --force --index-filter \
  'git rm --cached -r --ignore-unmatch bin' \
  --prune-empty --tag-name-filter cat -- --all

我按照下面的步骤将更改推送到github上的远程仓库

$ git push origin master --force

答案 1 :(得分:1)

唯一合理的地方是git rm之后。我自己没试过,但我觉得应该有用吗?

$ git filter-branch --force --index-filter \
  'git rm -r --cached --ignore-unmatch bin' \
  --prune-empty --tag-name-filter cat -- --all