在分离的HEAD状态下创建的git提交会发生什么情况? [英] What happens to git commits created in a detached HEAD state?
问题描述
这是发生了什么:
我有一个分支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屋!