Git 最近的一项变化改变了.git
使用子模块时处理目录。
而不是拥有一个.git
每个子模块,现在所有内容都位于“根级别”.git
目录(与包括子模块的工作副本相对应的目录)。
然后,在每个子模块中,创建一个文件,该文件指向该子模块的新位置.git
目录。
In 我的项目 https://github.com/roboptim/roboptim-core,我有以下.gitmodules
file:
[submodule "tests/shared-tests"]
path = tests/shared-tests
url = git://github.com/roboptim/roboptim-shared-tests.git
[submodule "cmake"]
path = cmake
url = git://github.com/jrl-umi3218/jrl-cmakemodules.git
当我做git clone --recursive
,然后我得到:
$ cat cmake/.git
gitdir: /home/moulard/profiles/default-x86_64-linux-ubuntu-12.04.1/src/unstable/roboptim/roboptim-core/.git/modules/cmake
我目前使用的是 Git 1.8.1.5。
我的问题是:
- 为什么这种行为发生了变化?我没有看到这个新策略有任何明显的好处。
- 我怎样才能安全地移动工作副本? (如果我移动工作副本,我会收到一条错误消息,告诉我损坏的 gitdir 的路径不再是 Git 存储库)
请注意,这与上一个问题不同移动包含子模块的 git 存储库的父目录 https://stackoverflow.com/questions/13252529/moving-the-parent-directory-of-a-git-repository-that-contains-submodules从某种意义上说,我是sure这不是与我的绝对路径的存在相关的问题.gitmodules
file.
The .git/module
组织的历史可以追溯到git1.7.8(2011 年 12 月 2 日) https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.8.txt#L109-L114:
当使用“填充新的子模块目录时git submodule init
", the $GIT_DIR
子模块的元信息目录在里面创建$GIT_DIR/modules/<name>/
超级项目的目录并通过 gitfile 机制引用。
这是为了可以在树中具有和不具有子模块的超级项目中的提交之间进行切换,而无需重新克隆.
然而,最近的错误修复已包含在1.8.2.1 https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.1.txt#L51-L52 and 1.8.3 https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.3.txt#L408-L409(2013 年 4 月 22 日):
“git submodule update”,当递归到子子模块时,没有累积前缀路径。
因此升级到最新的 git 版本可以解决这个问题。
这里,提到了一种可能的解决方案(最新的 git 1.8.3,2013 年 4 月 22 日)托马斯·莫拉德 https://stackoverflow.com/users/1442517/thomas-moulard in 评论 https://stackoverflow.com/questions/16160993/moving-a-git-working-copy-containing-submodules/16161950?noredirect=1#comment23103265_16161950:
$ git submodule deinit -f .
工作中!
然后我就可以跑了git submodule init
并且路径得到修复
如果(取消)初始化步骤(.git/modules
)
它不关心 'add
' 这一步记录了子模块的 url.gitmodules
文件:您仍然需要在该文件中手动删除它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)