仅从"git子模块“的结果来判断,这显然是一个常见的、容易混淆的话题,所以我将尽量精确。
忘记关于更新/提交/分支子模块的一切(我非常理解这会使事情复杂化),为什么每次更改分支时子模块都会被清空呢?根据我目前的理解,使分支机构的变得昂贵;如果我在机场,并且无法轻松/廉价地连接,该怎么办?我是不是做错了什么,或者我还没有意识到一些开发哲学?
例句不伤人:
## make a new project
$> git --version
git version 1.7.5.4
$> mkdir new_proj; cd new_proj; git init
$> touch new_file_1.txt; touch new_file_2.txt
$> git add . && git commit -m "first commit"
## move into some development branch
$> git checkout -b cool_feature
$> <hack hack hack>
# in the middle, I add a submodule
$> git submodule add https://github.com/some/other_proj.git other_proj
$> git submodule update --init
$> ls -lR
new_file_1.txt
new_file_2.txt
other_proj
other_proj/that_file
other_proj/another_file
## I have to go back to master to do some work
$> git checkout master
# Why is other_proj still around?
$> git status
Untracked: other_proj
## Fine, I'll remove it, since I want a clean working copy, because I need to do some work and commits
$> git clean -f -d
$> <work work work>
## Now I'm ready to go back to cool_feature, but my submodules are empty!
$> git checkout cool_feature在这一点上,我应该使用git submodule update,但是如果我不能/它是昂贵的(例如,它是远程的,而且我没有互联网接入/它很慢)。
我想出的最佳解决方法是将我关心的所有子模块克隆到一个完全独立的位置,然后将子模块从本地克隆中克隆出来;这保留了子模块的成本。当然,当您在团队中工作时,这会增加另一层复杂性。:/
发布于 2011-10-19 06:11:26
考虑到子模块只不过是一个pointer to a commit of another repo,git submodule update有点不可避免(为了返回与所述指针相关联的内容)。
另一个解决办法是克隆您的主要回购程序:
从一个分支切换到另一个分支并不需要git checkout (及其关联的git submodule update),而是路径的改变。
如果您想要在一个目录中工作,则另一个解决方案已在"Replaced third party code with git submodules, now I can't switch branches“中描述过。
在切换到
master分支
之前将子模块目录移开
https://stackoverflow.com/questions/7816023
复制相似问题