撤消git重置? [英] Undoing git reset?

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

问题描述

撤销

  git reset HEAD〜

命令?
目前,我能想到的唯一方法是从远程回购站点执行git clone http:// ...。

解决方案简短回答:

  git reset'HEAD @ {1}'



长答案:



Git记录所有ref更新,结帐,重置,提交,合并)。您可以输入以下内容来查看:

  git reflog 

此列表中的某处是您丢失的提交。假设你只是键入 git reset HEAD〜并且想撤消它。我的reflog如下所示:

  $ git reflog 
3f6db14 HEAD @ {0}:HEAD〜:更新HEAD
d27924e HEAD @ {1}:checkout:从d27924e0fe16776f0d0f1ee2933a0334a4787b4c
[...]

第一行说 HEAD 0位置前(换句话说,当前位置)是3f6db14;它是通过重置为 HEAD〜获得的。第二行表示 HEAD 1位置前(换句话说,复位前的状态)为d27924e。它是通过检查一个特定的提交获得的(尽管现在这不重要)。因此,要撤销重置,请运行 git reset HEAD @ {1} (或 git reset d27924e )。 p>

另一方面,如果您从那以后运行了其他一些更新HEAD的命令,那么您想要的提交将不在列表顶部,而您需要搜索 reflog



最后一个注意事项:查看 reflog 为您想要重置的特定分支,请说master,而不是 HEAD

  $ git reflog show master 
c24138b master @ {0}:合并origin / master:快进
90a2bf9 master @ { 1}:merge origin / master:Fast-forward
[...]

应该比一般的 HEAD reflog 有更少的噪音。


What's the simplest way to undo the

git reset HEAD~

command? Currently, the only way I can think of is doing a "git clone http://..." from a remote repo.

解决方案

Short answer:

git reset 'HEAD@{1}'

Long answer:

Git keeps a log of all ref updates (e.g., checkout, reset, commit, merge). You can view it by typing:

git reflog

Somewhere in this list is the commit that you lost. Let's say you just typed git reset HEAD~ and want to undo it. My reflog looks like this:

$ git reflog
3f6db14 HEAD@{0}: HEAD~: updating HEAD
d27924e HEAD@{1}: checkout: moving from d27924e0fe16776f0d0f1ee2933a0334a4787b4c
[...]

The first line says that HEAD 0 positions ago (in other words, the current position) is 3f6db14; it was obtained by resetting to HEAD~. The second line says that HEAD 1 position ago (in other words, the state before the reset) is d27924e. It was obtained by checking out a particular commit (though that's not important right now). So, to undo the reset, run git reset HEAD@{1} (or git reset d27924e).

If, on the other hand, you've run some other commands since then that update HEAD, the commit you want won't be at the top of the list, and you'll need to search through the reflog.

One final note: It may be easier to look at the reflog for the specific branch you want to un-reset, say master, rather than HEAD:

$ git reflog show master
c24138b master@{0}: merge origin/master: Fast-forward
90a2bf9 master@{1}: merge origin/master: Fast-forward
[...]

This should have less noise it in than the general HEAD reflog.

这篇关于撤消git重置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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