签出最近的提交后,为什么我有一个分离的HEAD? [英] Why do I have a detached HEAD after checking out the most recent commit?
问题描述
最近,在git存储库中工作时,我想在旧提交(68cce45
)上查看代码,所以我做了
Recently, while working in a git repository, I wanted to view the code at an old commit (68cce45
), so I did
git checkout 68cce45
查看更改后,我想返回到存储库的当前版本并继续工作.由于2bcfd11
是最新提交,我做了
After viewing the changes, I wanted to return to the current version of the repository and keep working. Since 2bcfd11
was the most recent commit, I did
git checkout 2bcfd11
然后我做了一些更改并做了
I then made some changes and did
git add *
然后
git status
向我发出警告:HEAD detached at 2bcfd11
.
我很困惑.我可以理解,如果我检出的最后一个提交是多个版本之前的,为什么我会处于分离的HEAD状态".但是,由于我签出的最后一次提交是存储库的最新版本,那么为什么我会处于分离的HEAD状态? HEAD现在不是指向存储库的顶部"吗?
I'm confused. I can understand why I would be in a "detached HEAD state" if the last commit I checked-out was several versions ago. But since the last commit I checked-out was the most current version of the repository, then why would I be in a detached HEAD state? Isn't HEAD now pointing to the "top" of the repository?
推荐答案
为什么我会处于分离的HEAD状态?
why would I be in a detached HEAD state?
因为您已经签出了提交而不是分支.检出所有提交-您处于分离的HEAD状态.
Because you've checked out a commit instead of a branch. Checkout any commit — and you're in a detached HEAD state.
HEAD现在不是指向存储库的顶部"吗?
Isn't HEAD now pointing to the "top" of the repository?
git
并不真正知道它是否是顶部.您必须通过签出分支向git
进行解释:
git
doesn't really knows if it's the top. You have to explain that to git
by checking out a branch:
git checkout master
现在git
知道它是已知分支的负责人.分离式HEAD问题的结束.
Now git
knows it's the head of a known branch. The end of detached HEAD problem.
这篇关于签出最近的提交后,为什么我有一个分离的HEAD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!