git filter-branch 拒绝后的 git push

17

我要将一个git仓库分为3个,我已经使用从 Git 仓库中分离(移动)子目录来将文件夹分离并成功地推送到了新的git仓库。在原有的仓库中,我使用了以下命令清除已移动的目录。

git filter-branch -f --index-filter "git rm -q -r -f --cached --ignore-unmatch lib/xxx/$REPO" --prune-empty HEAD

现在当我在原始代码库上执行 git st 命令时,会得到以下输出:

# On branch 1.5.0
nothing to commit (working directory clean)

当我尝试执行git push时,我得到以下错误:

 ! [rejected]        1.5.0 -> 1.5.0 (non-fast-forward)
error: failed to push some refs to 'git@github.com:/xxx/.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

我的猜测是使用-f选项:git push -f origin <branch>,但我希望确认一下,因为这将修改我的现有仓库。

1个回答

22

使用filter branch命令会使您的仓库与远程仓库不同。因此,您会发现远程仓库在推送时会拒绝,同时发出警告。在这种情况下,您计划强制更改仓库以与您筛选后的版本匹配,然后可以使用强制标志进行推送。但请注意,不应该像这样更改已发布的仓库 - 但如果您想更改也是可以的。请记住需要通知任何拥有克隆副本的人 - 但如果没有其他人,则可以继续操作。

如果您想非常小心 - 现在可以创建原始仓库的另一个克隆。然后再进行推送。如果出现问题,您可以使用备份仓库中的 push --mirror 命令将其强制还原。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接