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

标签 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

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

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

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

谢谢

最佳答案

好的,所以我需要做的就是将 -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

关于git - 从 git 中删除历史记录 - git 命令失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18746580/

相关文章:

git - 如何在克隆时传播 Git Hooks

django - Heroku 崩溃 : at=error code=H10 desc ="App crashed" method=GET path ="/"

git - 在 github.com 中 fork 私有(private) git repo

javascript - 使用哪个 wmd-editor 存储库

elasticsearch - Logstash正在将旧数据放入Elasticsearch。无法清除Elasticsearch数据

apache-kafka - Kafka 保留政策未按预期工作

hadoop - 删除 hdfs 中早于 N 天的分区文件夹

git - 为什么我的 repo 协议(protocol)的 github 页面中没有问题选项卡?

git - 应用 git stash 时如何忽略空格?

git - 如何同步不同存储库中的两个分支