如何解决git HEAD 分离 *from* vs 分离 *at* 分离:未分离:
我不是 git 新手。我知道分离的 HEAD 是什么,我可以签出一个新的分支来继续前进。但是今天我看到的是 detached from
消息而不是 detached at
消息。在尝试中止包含 2 个子模块的存储库中的合并时,我的一个子模块陷入了这种状态:
so_is_my_nacho_cheese$ git status
HEAD detached from 9733eeb0
nothing to commit,working tree clean
问题 1:
from 部分让我失望。我习惯看到at
。这个提交指的是什么?这是 HEAD 在被移动到无分支提交之前的最后一个位置吗?就我而言,该提交位于子模块 reflog 中,但它在 HEAD@{7}
处向下 7 层。这似乎不是 HEAD 的最后一个位置。但是因为这是父模块中中止合并的结果,因此可能无法追踪 HEAD 的运动。这个 detached from
提交通常指的是什么?
问题 2:
为了增加我的困惑,根据 git log,我的 HEAD 是 指向子模块中的一个分支:
so_is_my_nacho_cheese$ git log --graph --oneline -n 5
* ba737d3b (HEAD,xdhmoore_pascal) Just to record pascal run
* 5b69ce96 Fix fine_tune_checkpoint_loading
* 21dc78b2 Just docker changes applied to base
* 9733eeb0 (xdhmoore_base) Updating center_net_mobilenet_v2_fpn_feature_extractor to support classification finetuning.
* 63ec7359 Adding float feature to dataset_util
为什么 git status
告诉我我的 HEAD 是分离的(from 9733eeb0
,虽然不是 at 什么提交)而 git log
说它指向 ba737d3b
?
解决方法
当分离的 HEAD
指向首次检出的提交时,git status
表示 detached at <the_base_commit>
。如果然后您进行新提交或使用 git reset
将 HEAD
移动到另一个提交,例如到其父项,git status
表示 detached from <the_base_commit>
。然后,如果您将 HEAD
重置回基本提交,git status
会再次说 detached at <the_base_commit>
。
基本提交记录在 HEAD
的引用日志中,在 .git/logs/HEAD
中。如果您删除 .git/logs/HEAD
,git status
会显示 Not currently on any branch
,因为它现在找不到基本提交。
在我的理解中我遗漏的一个关键项目是,您仍然可以拥有一个分离的 HEAD,同时指向一个带有分支的提交。如果您没有分离,日志将显示带有箭头的 HEAD ->
:
分离:
so_is_my_nacho_cheese$ git log -n 1 --oneline --graph
* ba737d3b (HEAD,xdhmoore_pascal) Just to record pascal run
未分离:
so_is_my_nacho_cheese$ git log -n 1 --oneline --graph
* ba737d3b (HEAD -> xdhmoore_pascal) Just to record pascal run
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。