小团队.一位同事origin:master
误入歧途.他已经重置了他的本地仓库,但不能push -f
到Github,因为回购受到保护.
我已经fetch
编辑了回购,但没有将他的错误提交合并到我当地master
......但是.
我怎么能,假设我可以push -f
来源,重置origin
Github,以便它反映出他错误之前的状态?
$ 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
在我可以接受之前,我是否真的需要整合糟糕的提交(与),reset hard 2860a4c
然后push -f origin
呢?
我只是不想让事情变得更糟.
假设您有权限,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的机器上,做step 1
对step 3
,然后做git pull
合并远程修改
如果您没有权限git push -f
,请执行以下操作:
git pull git revert# may get it via "git log" git push
使用时git revert
,将删除已还原提交的更改,但此提交将保留在提交历史记录中.