Git失去了提交 [英] Git lost commits

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

问题描述

我试图在git中修复一个问题,并且意外地使用了git reset --hard来解决一些以前的提交问题。所以现在我不能回到老头了。

但是我在做这件事之前克隆了存储库,因此我将缺少的提交返回原始。这似乎昨天工作,但今天我看到,原来仍然坚持一个旧的承诺,新的似乎并不存在。
试图再次从克隆推送新的提交不起作用,因为git告诉我所有内容都是最新的。



我该如何解决这个问题?

解决方案

为了让您的HEAD回到正确的位置:


  1. git reflog 来获取HEAD最近 的列表。 www.kernel.org/pub/software/scm/git/docs/git-show.htmlrel =noreferrer> git show sha1 找到你希望你的HEAD的位置。

  2. 一旦你找到你想要的提交, git merge 让您的主人回到正确的位置。

一些解释:在 git commit中,没有任何东西指向一个提交给发生在它后面的提交。当您重置HEAD时,您将其指向较旧的提交。你以前的头像现在没有任何指向它的



我们使用 reflog 来查看HEAD最近在哪里。一旦它回到你想要的位置,你将主人或其他分支指向那个地方,一切都很好!


I was trying to fix a problem in git and accidentally used git reset --hard to some previous commit. So now I cannot get back to the old head.

However I did clone the repository before I did this, and so I pushed the missing commits back to the original. This seemed to work yesterday, but today I see that the original is still stuck on an old commit and the new ones seemingly don't exist. Trying to push the new commits from the clone again don't work as git tells me everything is up to date.

How do I fix this?

解决方案

To get your HEAD back in the right place:

  1. git reflog to get a list of where HEAD has been lately.
  2. git show sha1 to find the spot you want your HEAD to be.
  3. Once you find the commit you want, git merge to get your master back into the right spot.

Some explanation: In a git commit there is nothing pointing one commit to the one that happend after it. When you reset the HEAD, you pointed it to an older commit. Your previous head is now dangling without anything pointing to it.

We use reflog to see where HEAD has been lately. Once it is set back to where you want it, you point the master, or some other, branch back to that spot and all is well!

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

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