子模块具有分离头,因为子模块意味着“检查子模块存储库中的特定提交”。 master
分支可能已经向前移动(它可能指向从落实0b6a803
下降的提交),所以Git检出特定修订而不是检出分支。
git-submodule
可以选择记录分支名称。当你这样做,你可以使用git submodule update --remote
与分支更新子模块:
# Add the submodule with the "master" branch referenced
git submodule add -b master https://github.com/holms/chef-starter.git chef-starter
# When you want to update the submodule:
git submodule update --remote
# You'll still need to commit the submodule if you want future checkouts to use the new revision
git add chef-starter
git commit -m "Update chef-starter submodule"
你还是辅助模块获得一个分离的头,当你开始检查出不同版本的超级项目(vagarant-starter
)的,但至少现在更容易将子模块从远程更新到最新版本。
您可能会发现它更容易使用git的子树,而不是子模块:
# First, get rid of the submodule
git submodule deinit chef-starter # If you have Git 1.8.3 or later, otherwise edit .gitmodules
git rm chef-starter # Remove the directory
git commit -m "Removed chef-starter submodule in preparation to add as a subtree"
# Now add the subtree
git subtree add -P chef-starter https://github.com/holms/chef-starter master --squash
该移植物chef-starter
回购进入chef-starter/
目录在vagrant-starter
回购。从那时起,如果您选择编辑子树中的文件,则不必做任何特别的事情。例如,克隆后不必运行git submodule update
。
'git clone --recursive URL dir; cd dir; git submodule foreach'git checkout origin/master || :'' –
好的,当你在repo目录上执行git status的时候,你会在执行最后一次签出命令后看到“等待提交”。这是我不想要的。 – holms