2

我对 git并不陌生。我知道分离的 HEAD 是什么,我可以签出一个新的分支来继续前进。但是今天我看到的是一条detached from消息而不是一条detached at消息。在尝试中止包含 2 个子模块的 repo 中的合并时,我的一个子模块陷入了这种状态:

so_is_my_nacho_cheese$ git status

HEAD detached from 9733eeb0
nothing to commit, working tree clean

问题一:

从部分让我失望我见惯了at。这个提交是指什么?这是 HEAD 在被移动到无分支提交之前的最后一个地方吗?就我而言,该提交位于子模块 reflog 中,但它位于HEAD@{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 是分离的( 9733eeb0,虽然不是什么提交),而git log说它是指向的ba737d3b

4

2 回答 2

6

HEAD第一次签出的提交处的分离点时,git statusdetached at <the_base_commit>. 如果然后你做出新的提交或使用git reset移动HEAD到另一个提交,例如到它的父级,git statusdetached from <the_base_commit>。如果然后你重置HEAD回基本提交,再次git statusdetached at <the_base_commit>

基本提交记录在HEAD的 reflog 中,在.git/logs/HEAD. 如果您删除.git/logs/HEADgit status则表示Not currently on any branch它现在找不到基本提交。

于 2021-02-09T03:19:26.270 回答
2

我的理解中缺少的一个关键项目是,在指向带有分支的提交时,您仍然可以拥有一个分离的 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
于 2021-02-09T04:28:02.087 回答