如何在git中撤消结帐? [英] How do I undo a checkout in git?

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

问题描述

我刚刚从我的本地git仓库中检出了一个早期的提交。我没有做任何改变,我只是看着它。现在我想回到我最新的提交 - 我该怎么做?

I just checked out an earlier commit from my local git repo. I haven't made any changes to it, I was just looking at it. Now I want to go back to my latest commit - how do I do that?

我用来检查它的确切命令:

The exact command I used to check it out:

git checkout e5dff6b3c5d704f9b598de46551355d18235ac08

现在,当我输入git log,在顶部我看到这个签出提交,但我后来没有提交。我是否意外删除了这些内容?

Now when I type git log, at the top I see this checked out commit, but none of my later commits. Did I accidentally delete those?

推荐答案

试试这个:

Try this first:

git checkout master

(如果您位于与 master ,改为使用分支名称。)

(If you're on a different branch than master, use the branch name there instead.)

如果不行,试试...

If that doesn't work, try...

对于单个文件:

For a single file:

git checkout HEAD /path/to/file

对于整个存储库工作副本:

For the entire repository working copy:

git reset --hard HEAD

如果这不起作用,那么你可以在reflog中找到你的老头SHA并重置为:

And if that doesn't work, then you can look in the reflog to find your old head SHA and reset to that:

git reflog
git reset --hard <sha from reflog>

HEAD 是一个总是指向您当前分支中的最新提交。

HEAD is a name that always points to the latest commit in your current branch.

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

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