Git子模块仍然具有分离头

Git子模块仍然具有分离头,git,git-submodules,Git,Git Submodules,当我获取使用子模块的git项目时,子模块有一个分离的头。我在这里读了很多关于stackoverflow的帖子,他们说这个问题应该得到解决——所以我做错了什么,但没发现是什么 事情就是这样: M.Grunwald % git clone -b BranchName ssh://git@10.128.28.106:7999/~m.grunwald/repo_with_submodules.git some_repo Cloning into 'some_repo'... remote: Counti

当我获取使用子模块的git项目时,子模块有一个分离的头。我在这里读了很多关于stackoverflow的帖子,他们说这个问题应该得到解决——所以我做错了什么,但没发现是什么

事情就是这样:

M.Grunwald % git clone -b BranchName ssh://git@10.128.28.106:7999/~m.grunwald/repo_with_submodules.git some_repo
Cloning into 'some_repo'...
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 26 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (26/26), done.
Resolving deltas: 100% (9/9), done.
M.Grunwald % cd some_repo
M.Grunwald % cat .gitmodules


[submodule "Library/MyLib"]
        path = Library/MyLib
        url = ssh://git@10.128.28.106:7999/~m.grunwald/my_lib.git
        branch = BranchName


M.Grunwald % git submodule init
Submodule 'Library/MyLib' (ssh://git@10.128.28.106:7999/~m.grunwald/my_lib.git) registered for path 'Library/MyLib'
M.Grunwald % git submodule update --remote
Cloning into
'/cygdrive/c/Users/m.grunwald/Documents/TMP/some_repo/Library/MyLib'...
Submodule path 'Library/MyLib': checked out '5c665e00cca5eb24d9b615294807520a6036fa90'
git submodule update --remote  4.31s user 10.61s system 10% cpu 2:21.52 total
M.Grunwald % cd Library/MyLib
M.Grunwald % git status
HEAD detached at 5c665e0
nothing to commit, working tree clean
因此,.gitmodules包含子模块,包括“branch=branchname”,我用--remote调用子模块update。。。还缺少什么

%git——版本 git版本2.12.3

如果我切换到BranchName,就会发生这种情况(cwd是某种_repo/Library/MyLib):

M.Grunwald%git分支-r
原点/头部->原点/主控
起源/分支名称
M.Grunwald%git签出分支机构名称
Branch BranchName设置为从原点跟踪远程BranchName。
切换到新分支“BranchName”
M.Grunwald%git状态
在树枝上
您的分支机构使用“origin/BranchName”更新。
没什么要承诺的,正在清理树
格伦瓦尔德先生%cd。。
格伦瓦尔德先生。。
M.Grunwald%git状态
在树枝上
您的分支机构使用“origin/BranchName”更新。
未为提交而暂存的更改:
(使用“git add…”更新将提交的内容)
(使用“git签出--…”放弃工作目录中的更改)
(提交或放弃子模块中未跟踪或修改的内容)
修改:库/MyLib(新提交)
M.Grunwald%git差异库/MyLib
diff——git a/Library/MyLib b/Library/MyLib
索引1341b30..5c665e0 160000
---a/Library/MyLib
+++b/图书馆/MyLib
@@ -1 +1 @@
-子项目提交1341b30ae55df1afc7265a9110fbf09661dd627b
+子项目提交5c665e00cca5eb24d9b615294807520a6036fa90

在我看来很正常。你到底有什么问题?子模块始终处于分离头状态,即使它正确设置为跟踪分支(请参阅下面的链接)。在父存储库中切换分支时,必须运行
git submodule update
将子模块更新为新分支的提交(如果不同)

从,这似乎正是你想知道的:

请注意,对于每个更新的子模块,结果总是 正如丹·卡梅隆在回答中所指出的,超然的头


我觉得很正常。你到底有什么问题?子模块始终处于分离头状态,即使它正确设置为跟踪分支(请参阅下面的链接)。在父存储库中切换分支时,必须运行
git submodule update
将子模块更新为新分支的提交(如果不同)

从,这似乎正是你想知道的:

请注意,对于每个更新的子模块,结果总是 正如丹·卡梅隆在回答中所指出的,超然的头


您使用的是什么版本的Git?如果您在子模块中签出
BranchName
,您是否看到超级项目中发生了更改?您好,Nils,请查看我的更新。子模块中分离头的唯一问题是当您需要提交更改时。然后,您只需要记住在提交这些更改之前签出相应的分支。您使用的是什么版本的Git?如果您在子模块中签出
BranchName
,您是否看到超级项目中的更改?您好,Nils,请参阅我的更新可能的重复。子模块中分离头的唯一问题是当您需要提交更改时。然后,您只需要记住在提交这些更改之前签出相应的分支。
M.Grunwald% git branch -r
  origin/HEAD -> origin/master
  origin/BranchName
M.Grunwald % git checkout BranchName
Branch BranchName set up to track remote branch BranchName from origin.
Switched to a new branch 'BranchName'
M.Grunwald % git status
On branch BranchName
Your branch is up-to-date with 'origin/BranchName'.
nothing to commit, working tree clean
M.Grunwald % cd ..
M.Grunwald % ..
M.Grunwald % git status
On branch BranchName
Your branch is up-to-date with 'origin/BranchName'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

        modified:   Library/MyLib (new commits)

M.Grunwald % git diff Library/MyLib
diff --git a/Library/MyLib b/Library/MyLib
index 1341b30..5c665e0 160000
--- a/Library/MyLib
+++ b/Library/MyLib
@@ -1 +1 @@
-Subproject commit 1341b30ae55df1afc7265a9110fbf09661dd627b
+Subproject commit 5c665e00cca5eb24d9b615294807520a6036fa90