~/main-module$ git submodule status +773275124c59b906da71e892b2f9d53c633bc252 sub-module (heads/master)
~/main-module$ git status On branch v2.0 Your branch is up-to-date with 'origin/v2.0'. 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)
modified: sub-module (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
~/main-module$ git status On branch v2.0 Your branch is up-to-date with 'origin/v2.0'. 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)
modified: sub-module (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
========
~/main-module/sub-module$ git status On branch master Your branch is up-to-date with 'origin/master'. nothing to commit, working directory clean
使用了 git submodule update 之后,两个仓库的 git status 信息变成了这个样子:
1 2 3 4 5 6 7 8 9 10
~/main-module$ git status On branch v2.0 Your branch is up-to-date with 'origin/v2.0'. nothing to commit, working directory clean
========
~/main-module/sub-module$ git status HEAD detached at 359bce6 nothing to commit, working directory clean
这样,主仓库的开发者就可以从一个干净的空间开始工作了。
疑难杂症
还记得我们是从 v2.0 分支引入子模块的么?假如现在要查看 v1.0 分支,会发生什么呢?
1 2 3 4 5
~/main-module$ git checkout v1.0 error: The following untracked working tree files would be overwritten by checkout: sub-module/sub.txt Please move or remove them before you can switch branches. Aborting
~/main-module$ git checkout -f v1.0 warning: unable to rmdir sub-module: Directory not empty Switched to branch 'v1.0' Your branch is up-to-date with 'origin/v1.0'.
~/main-module$ git checkout v2.0 M sub-module Switched to branch 'v2.0' Your branch is up-to-date with 'origin/v2.0'.
~/main-module$ git status On branch v2.0 Your branch is up-to-date with 'origin/v2.0'. 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: sub-module (modified content)
no changes added to commit (use "git add" and/or "git commit -a")