重置远程某个提交 [英] Resetting remote to a certain commit

查看:70
本文介绍了重置远程某个提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想放弃在commit < commit-hash> 之后完成的所有更改。
所以我做了:

  git reset --hard< commit-hash> 

现在我想对我的遥控器做同样的事情。我怎样才能做到这一点?我在< commit-hash> 之后做了一些提交(并且推送),我只是想放弃它们。只是某些方面错了,我不想让它变得比现在更糟糕。 ;(

我基本上想把我的 origin / master 倒回到< commit-散列>

解决方案

假设您的分支名为 master 在这里和远程,并且你的远程被称为 origin 你可以这样做:

  git reset --hard< commit-hash> 
git push -f origin master

但是,如果其他人正在使用远程存储库并且已经取消了更改,则应该避免这样做。在这种情况下,最好恢复您不需要的提交,然后按正常推送。



更新:你已经在下面解释过,其他人已经撤回了你推送的更改,所以最好创建一个新的提交来恢复所有这些更改对你的选择有一个很好的解释离子在来自JakubNarębski的这个答案。哪一个最方便取决于您想要还原的提交数量,以及哪种方法对您最有意义。



由于您的问题很明显,您已经使用过 git reset --hard 重置您的 master 分支,您可能需要先使用 git reset --hard ORIG_HEAD 将分支移回原来的位置。 (一如既往 git reset --hard ,确保 git status 干净,你在并且你知道 git reflog 作为恢复明显丢失的提交的工具。)你还应该检查 ORIG_HEAD 指向正确的提交,使用 git show ORIG_HEAD


I want to discard all changes done after commit <commit-hash> . So I did:

git reset --hard <commit-hash>

Now I want to do the same with my remote. How can I do this? I have done some commits (and pushes) after <commit-hash> and I just want to discard them all. Is just something went terribly wrong in the way and I don't want to make it worse than it is already. ;(

I basically want to rewind my origin/master to <commit-hash>

解决方案

Assuming that your branch is called master both here and remotely, and that your remote is called origin you could do:

 git reset --hard <commit-hash>
 git push -f origin master

However, you should avoid doing this if anyone else is working with your remote repository and has pulled your changes. In that case, it would be better to revert the commits that you don't want, then pushing as normal.

Update: you've explained below that other people have pulled the changes that you've pushed, so it's better to create a new commit that reverts all of those changes. There's a nice explanation of your options for doing this in this answer from Jakub Narębski. Which one is most convenient depends on how many commits you want to revert, and which method makes most sense to you.

Since from your question it's clear that you have already used git reset --hard to reset your master branch, you may need to start by using git reset --hard ORIG_HEAD to move your branch back to where it was before. (As always with git reset --hard, make sure that git status is clean, that you're on the right branch and that you're aware of git reflog as a tool to recover apparently lost commits.) You should also check that ORIG_HEAD points to the right commit, with git show ORIG_HEAD.

这篇关于重置远程某个提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆