过去我用过git filter-branch
从我的 git 历史记录中删除文件。接下来,我可以强制推送来更新远程存储库。例如,从本地存储库中删除所有 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.
当我检查时,filter-repo 命令似乎已删除我的远程 URLgit remote -v
。手动添加回遥控器让我陷入了其他设置无效的困境。
为什么git-filter-repo
删除我的遥控器?我如何使用重写遥控器的历史记录git-filter-repo
就像我能做到的git filter-branch
?
为什么 git-filter-repo 会删除我的遥控器?
文档 https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html在标题为的部分中解释了他们的推理内部结构 https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#INTERNALS:
- 我们不希望用户意外推回原始存储库,如中所述讨论 https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#DISCUSSION。它还提醒用户,由于历史已被重写,此存储库不再与原始存储库兼容。最后,另一个小好处是,这允许用户使用
--mirror
选择他们的新家,而不会意外发送远程跟踪分支。
如何使用 git-filter-repo 重写远程历史记录,就像使用 git filter-branch 一样?
只需使用git remote add
to put origin
返回,或者——因为命令序列中的步骤 3 是git remote rm origin
—just rename origin
首先改成其他名字。但如果您这样做,请注意步骤 2。
你说:
手动添加回遥控器让我陷入了其他设置无效的困境。
显然,您需要在这里详细说明。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)