Mat*_*att 6 git git-submodules
仅从SO上的"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
Run Code Online (Sandbox Code Playgroud)
在这一点上,我应该git submodule update,但如果我不能/它很昂贵(例如它是远程的,我没有互联网访问/它很慢).
我提出的最好的解决方法是将我关心的所有子模块克隆到一个完全独立的位置,然后从我的本地克隆中复制子模块; 这保留了子模块的廉价.当然,当你在团队中工作时,这会增加另一层复杂性.:/
考虑到子模块只不过是指向另一个 repo 的提交的指针,这git submodule update是不可避免的(为了取回与所述指针关联的内容)。
另一种解决方法是克隆您的主存储库:
从一个分支切换到另一个分支不需要 a git checkout(及其关联的git submodule update),而是需要更改路径。
如果您想在一个目录中工作,另一种解决方法已在“用 git 子模块替换第三方代码,现在我无法切换分支”中进行了描述
master在切换到分支之前将子模块目录移开
| 归档时间: |
|
| 查看次数: |
679 次 |
| 最近记录: |