在分离的HEAD状态下创建的git提交会发生什么情况? [英] What happens to git commits created in a detached HEAD state?

查看:560
本文介绍了在分离的HEAD状态下创建的git提交会发生什么情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是发生了什么:

我有一个分支A.在分支A上,我犯了一系列的变化。我对代码不满意,所以我检查了分支A中的前一个提交。然后我做了更多更改并将它们提交到分支A上。现在我无法在任何地方找到此提交。我失去了这段代码吗?

解决方案

旧的提交仍在reflog中。

  git reflog 

这会显示一个列表的承诺,而失去承诺应该在那里。你可以把它变成一个新的分支。例如,如果SHA-1是ba5a739,那么您可以在旧的提交中创建一个名为new-branch的新分支:

  git branch new-branch ba5a739 

请注意,数据库被修剪。

This is what happened:

I have a branch A. On branch A I committed a bunch of changes. I was not happy with the code, so I checked out the previous commit in branch A. I then made a bunch more changes and committed them on branch A. Now I can not find this commit anywhere. Did I lose this code?

解决方案

The old commit is still in the reflog.

git reflog

This will show a list of commits, and the "lost" commit should be in there. You can make it into a new branch. For example, if the SHA-1 is ba5a739, then you can make a new branch named "new-branch" at the old commit with:

git branch new-branch ba5a739

Note that "lost" commits will get deleted when the database is pruned.

这篇关于在分离的HEAD状态下创建的git提交会发生什么情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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