【发布时间】:2021-02-25 17:37:49
【问题描述】:
过去我曾使用git filter-branch 从我的 git 历史记录中删除文件。之后,我可以强制推送来更新远程存储库。例如,从本地 repo 中删除所有 HTML 文件,然后重写远程以反映更改:
$ git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch -r \*.html' --prune-empty -- --all
$ git push origin --force --all
这工作得很好。但是看到filter-branch 非常慢并且已经被弃用了一段时间,我想用git-filter-repo 来代替。到目前为止,这似乎是等效的命令:
$ git-filter-repo --force --path-glob *.html --invert-paths
这第一步似乎奏效了。我的问题是当我之后尝试强制推送时,我看到我的遥控器丢失了。
$ git push origin --force --all
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
当我检查git remote -v 时,filter-repo 命令似乎删除了我的远程 URL。手动加回遥控器会让我陷入其他设置无效的兔子洞。
为什么git-filter-repo 会删除我的遥控器?以及如何使用 git-filter-repo 重写遥控器的历史记录,就像使用 git filter-branch 一样?
【问题讨论】:
-
有类似问题的朋友,可能需要将.git/config中的远程URL配置备份到
git filter-repo之前的其他地方,以备日后恢复。这在 Github docs 中有提及
标签: git git-filter-branch git-filter-repo