Github:重置为上一次提交

Github:重置为上一次提交,git,github,master,Git,Github,Master,小团队。一位同事误推到原点:master。他已重置其本地回购,但无法将-f推送到Github,因为回购受保护 我已经fetched了回购协议,但还没有将他的错误提交合并到我的本地master…中 假设我可以将-f推到origin,如何在Github上重置origin,使其反映出出错前的状态 $ git push origin 2860a4c:master To github.com:example/myproj.git ! [rejected] 2860a4c -> mas

小团队。一位同事误推到
原点:master
。他已重置其本地回购,但无法
将-f
推送到Github,因为回购受保护

我已经
fetch
ed了回购协议,但还没有将他的错误提交合并到我的本地
master
…中

假设我可以
将-f
推到origin,如何在Github上重置
origin
,使其反映出出错前的状态

$ git push origin 2860a4c:master
To github.com:example/myproj.git
 ! [rejected]        2860a4c -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:example/myproj.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
我真的需要集成坏提交(与git pull)吗?然后,我假设,
重置硬2860a4c
,然后
推送-f origin


我只是不想让事情变得更糟。

如果你能
推-f
,那就去做吧。如果您想要的状态是在顶部之前提交一次,则可以运行

git pull
git reset --hard @~1
git push -f

确保团队中的每个人都处于同步状态,这样他们就不会丢失任何工作。

您不需要拉坏提交,因此也不需要git reset。 如果我正确理解了这个问题,git push--force应该足够了。它会把遥控器的状态带给你


如果您已经拉坏了提交,请使用
git reset--hard
+
git push--force
,如下所示:。

以下是您可以执行的步骤,前提是您拥有
git push-f
的权限

在您的计算机上,执行以下操作:

# Step 1: Take the changes from remote
git pull

# Step 2: Note the commit to which you want for restoring your repo to 
# using `git log`. Say the commit id is "x". 
git log

# Step 3: Do hard reset for that commit. 
#         ** NOTE ** All the changes after the commit "x" will be removed
git reset --hard x    # where x is the commit id

# Step 4: Push to remote
git push -f
然后在collegue的机器上,执行
步骤1
步骤3
,然后执行
git pull
合并远程更改


如果您没有git push-f的权限,请执行以下操作:

git pull

git revert <commit id>   # may get it via "git log"

git push
git拉
git revert#可以通过“git日志”获取
git推送

使用git revert,将删除还原提交的更改,但此提交将保留在提交历史记录中

可能重复我知道这里有很多(太多?)关于恢复git提交的帖子。然而,我还没有找到一个能够清楚地解释如何删除(重置)Github上的最后一次提交。我想我可以
还原
提交,但我正在试图找到一种方法,只要撤销最后一次Github提交,如果可能的话,不破坏本地回购。如果没有
-f
,你就无法做到这一点。您需要使用git revert来还原提交,但这将是您历史的一部分。您是否有权执行
-f
“假设我有权
推-f
”因此,是的,我有权限(或者可以暂时授予它)。>假设我可以推-f到源站,我怎么能呢