Git子模块处于“分离的头部”克隆和子模块更新后的状态 [英] Git submodule is in "detached head" state after cloning and submodule update

查看:114
本文介绍了Git子模块处于“分离的头部”克隆和子模块更新后的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我克隆我的git repo时,其中一个子模块位于一个带有奇怪名称的分支中,我认为这意味着它有一个分离的头(我甚至不知道是什么如果我检查我的子模块的主分支,然后运行 git submodule update --init --recursive

有人知道发生了什么吗?

解决方案

div>

git目录的内容存储在简单的文本文件清单(即目录列表)中,名为树,如下所示,其中blob是文件的内容,而树还有更多像这样的树:

  100644 blob 0c31be662540ce902cee106f86bfdeef519fc662 .gitignore 
100644 blob 1d364edf530c2238e79162bf2d9f30c2af610347 .gitmodules
040000 tree fc6bc39202ec20228e9135cd426110c558b625cd foo
040000 tree 2f9fc460f3a2370ed45b39b2bcaaf9b6e746b823 bar

如果bar是一个子模块,而不是仅仅一个目录,那么包含它的树就会像这样列出:

  100644团块0c31be662540ce902cee106f86bfdeef519fc662的.gitignore 
100644团块1d364edf530c2238e79162bf2d9f30c2af610347 .gitmodules
040000树fc6bc39202ec20228e9135cd426110c558b625cd FOO
040000提交2f9fc460f3a2370ed45b39b2bcaaf9b6e746b823酒吧

请注意,不是bar是树,现在它是一个提交(在子模块中)。这是所有关于树/提交级子模块的git存储,所以它不知道提交是在哪个分支上进行的。事实上,存储分支名称是行不通的。他们可以改变。另外,如果您在回购中签出一个旧的提交,并且需要将子模块还原回去,那么分支应该移回子模块吗?这将在新的分支位置之后将提交投入到未引用的区域。



这些分支供人类使用,用于理解DAG,以及特定思路是。 Git不在乎我们如何引用提交。它需要一个具体的位置,以便您可以安全地移动包含回购站点,并且知道该子模块将始终检出到当时的位置。唯一的事实就是散列。


When I clone my git repo, one of the submodules is in a branch with a strange name, which I think means it has a "detached head" (I'm not even sure what that means).

If I checkout my main branch for the submodule, then run "git submodule update --init --recursive" it happens again.

Does anybody know what's going on?

解决方案

The contents of git directories are stored in simple text file manifests (i.e. directory listings) called "trees" that look like the following, where blobs are the contents of files, and trees are yet more trees like this one:

100644 blob 0c31be662540ce902cee106f86bfdeef519fc662    .gitignore
100644 blob 1d364edf530c2238e79162bf2d9f30c2af610347    .gitmodules
040000 tree fc6bc39202ec20228e9135cd426110c558b625cd    foo
040000 tree 2f9fc460f3a2370ed45b39b2bcaaf9b6e746b823    bar

If bar was a submodule, instead of merely a directory, however, the tree containing it would be listed like this:

100644 blob 0c31be662540ce902cee106f86bfdeef519fc662    .gitignore
100644 blob 1d364edf530c2238e79162bf2d9f30c2af610347    .gitmodules
040000 tree fc6bc39202ec20228e9135cd426110c558b625cd    foo
040000 commit 2f9fc460f3a2370ed45b39b2bcaaf9b6e746b823  bar

Note that instead of bar being a tree, it's now a commit (in a submodule). This is all git stores about a submodule at the tree/commit level, so it can't know what branch a commit was on. In fact, storing branch names can't work. They can change. Also, if you check out an old commit in your repo that needs to roll the submodule back as well, should the branch move back in the submodule? That would cast the commits after that new branch location into unreferenced territory.

The branches are for humans to use, to make sense of the DAG, and where particular lines of thought are. Git doesn't care how we refer to the commits. It needs a concrete location so you can safely move the containing repo around, and know that the submodule will always be checked out to where it was at that time. The only truth is the hash.

这篇关于Git子模块处于“分离的头部”克隆和子模块更新后的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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