当我获取使用子模块的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调用子模块更新...还缺少什么?
%git --version git版本2.12.3
如果我切换到BranchName会发生什么(cwd是some_repo / Library / MyLib):
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
答案 0 :(得分:0)
对我来说很正常。你的问题究竟是什么?子模块始终处于分离头状态,即使它已正确设置为跟踪分支(请参阅下面的链接)。在父存储库中切换分支时,必须运行git submodule update
以将子模块更新为新分支的提交(如果不同)。
来自this answer,它似乎准确地说明了您想知道的内容:
请注意,对于每个更新的子模块,结果始终为a 正如Dan Cameron在他的回答中所说的那样,脱离了HEAD。