Git:恢复到之前的提交状态
我很困惑。我想返回到我在“git log”中标识的先前提交。
但是当我执行“git checkout”时,我没有得到所说的提交。没有任何改变。 它告诉我我处于分离的 HEAD 模式,但我想要的文件不在那里。
我到底做错了什么?
B先生
I'm confused. I want to go back to a previous commit that I identified in "git log".
But when I do "git checkout ", I don't get said commit. Nothing changes.
It tells me I'm in detached HEAD mode, but the files I want are not there.
What the eff am I doing wrong?
MrB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
git reset --hard
从联机帮助页中:git checkout
用于将工作目录切换到不同的分支或提交。这不会将HEAD
移动到那里。git reset --hard <commit>
From the manpage:git checkout
is for switching your working directory to a different branch or commit. This does not move theHEAD
there.不要 git reset -hard 它是永久的!
请改用
!如果您不小心损坏了其中的一件作品,您仍然可以将其恢复。它永远不会被推送到你的遥控器,除非你选择通过创建一个分支并将其向上推来实现。
此外,您的方向是正确的,您可以使用 git checkout 来完成同样的事情。语法是
但是它和 git reset --hard 有着同样的问题。坚持藏起来,你将来就不会掉头发了。
更长的答案
上述解决方案会恢复您的所有更改。但是,您询问如何消除一些更改。为了完整起见,我将添加此内容。
为此,您可以
现在系统会提示您确切想要消失的内容...直至任何粒度级别。因此,如果您选择这样做,您可以安全地“拒绝”对单个文件的少量更改。
DO NOT git reset -hard it is PERMANENT!
Please use
instead! If you have a piece of work in there that you zapped by accident, you can still get it back. This never gets pushed to your remote unless you choose to do so by making a branch out of it and pushing it up.
Also, you are on the right track that you can use
git checkout
to accomplish the same thing. The syntax isBut it has the same problem as
git reset --hard
. Stick with stash and you will save losing your hair in the future.Longer answer
The above solutions revert all your changes. However, you asked how to get rid of some of the changes. I'll add this for completeness.
To do this, you can
You will now be prompted for what exactly you want to make dissappear... down to what ever level of granularity. So you can safely "reject" only a few changes to a single file if you choose to do so.
在 git 中,首先你得到了你的提交标识符,并使用该标识符你可以恢复你的提交
In git first you got your commit identifier and use that identifier you can revert your commit