【问题标题】:Removing history from git - git command fails从 git 中删除历史记录 - git 命令失败
【发布时间】:2013-09-15 19:06:06
【问题描述】:

我正在尝试从 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 本身保存在本地本地仓库中,因为这是我的工作目录。

谢谢

【问题讨论】:

    标签: git github purge


    【解决方案1】:

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

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

    我按照以下内容将更改推送到 github 上的远程 repo

    $ git push origin master --force
    

    【讨论】:

      【解决方案2】:

      唯一有意义的地方是git rm 之后。我自己没有尝试过,但我认为应该可以吗?

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

      【讨论】:

      • LOL 就在我尝试过的时候发布了!有文件的备份,所以我想我会继续把它扔到我认为最好的地方,如果出现问题,重新启动 repo。干杯吧
      • 附带说明,我必须使用" 代替',因为我遇到了错误(在Windows 机器上使用cmd
      猜你喜欢
      • 2023-01-30
      • 2014-06-19
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 2019-12-20
      • 2017-10-01
      相关资源
      最近更新 更多