远程 Git 分支的回滚操作

6

可能有重复:
如何将修改后的提交推送到远程 Git 仓库?
撤消 Git 推送

你好,

我使用以下命令从我的主分支中删除了一些提交:

git reset --hard SHA_VALUE

我在github上有一个远程版本的代码库,每当我使用git push命令时,会出现错误提示,提示我合并远程代码库中包含的更改(而我不想这样做)。

因此我的问题是,远程代码库中有哪个命令与git reset相当?

谢谢。


2
请参见此处:https://dev59.com/gXVC5IYBdhLWcg3wjx_u 或此处:https://dev59.com/L3M_5IYBdhLWcg3wslVW - CB Bailey
1
谢谢!git push origin +master:master 对我来说已经完成了。 - mvaz
在这种情况下,我投票将其关闭为“推送修改后的提交”的重复项,因为它具有与您尝试做的相同的解决方案和陷阱。 - CB Bailey
2个回答

6
您可以使用带有 "force" 选项的 "git push" 命令。
git push -f

通过手册文档:

   -f, --force
       Usually, the command refuses to update a remote ref that is not an ancestor of the local ref 
       used to overwrite it. This flag disables the check. This can cause the remote repository to 
       lose commits; use it with care.

1

我认为你需要执行 "git rebase" 操作。请查看 文章 中关于 rebase 的部分,阅读标题为 "常见的 Rebase 使用实践"。


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