过去我使用
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
输出:
致命:“origin”似乎不是 git 存储库 致命:无法从远程存储库读取。
请确保您拥有正确的访问权限 并且存储库存在。
The filter-repo command appears to have removed my remote URLs when I check `git remote -v`. Adding back the remote manually puts me down a rabbit hole of other settings be invalid.
Why does `git-filter-repo` remove my remote? And how can I rewrite remote's history using `git-filter-repo` like I'm able to with `git filter-branch`?
为什么 git-filter-repo 会删除我的遥控器?
- 我们不希望用户意外推回原始存储库,如讨论中所述。它还提醒用户,由于历史已被重写,此存储库不再与原始存储库兼容。最后,另一个小好处是,这允许用户使用
选项推送到他们的新家,而不会意外发送远程跟踪分支。--mirror
如何使用 git-filter-repo 重写远程的历史记录,就像我可以使用 git filter-branch 那样?
只需使用
git remote add
将 origin
放回原处,或者——由于命令序列中的步骤 3 是 git remote rm origin
——只需先将 重命名 origin
为其他名称即可。 但如果您这样做,请注意步骤 2。
你说:
手动添加回遥控器让我陷入了其他设置无效的困境。
显然,您需要在这里详细说明。
最近在搞git。 遇到同样的问题。
运行 git-filter-repo 后,我的“git Branch -r”没有返回任何内容。 为了恢复输出, 你需要:
git remote add origin xxxxxxxxxxx
git fetch --all
然后,您将得到“git Branch -r”输出。