最近Git的更改改变了使用子模块时处理.git
目录的方式。
现在,所有内容都位于“根级”.git
目录(与包含子模块的工作副本相对应的目录)中,而不是每个子模块只有一个.git
。
然后,在每个子模块中,创建一个指向.git
目录新位置的文件。
在my project中,我有以下.gitmodules
文件:
[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。
我的问题是:
请注意,这与上一个问题Moving the parent directory of a git repository that contains submodules不同,因为我确定这不是我的{中存在绝对路径相关的问题{1}}档案。
答案 0 :(得分:8)
.git/module
组织的日期可以追溯到git1.7.8 (December 2d, 2011):
当使用“
git submodule init
”填充新的子模块目录时,子模块的$GIT_DIR
元信息目录在超级项目的$GIT_DIR/modules/<name>/
目录中创建,并通过gitfile机制引用。
这样可以在超级项目中提交,在没有重新克隆的情况下在树中具有和没有子模块。
但是,最近的错误修复已包含在1.8.2.1和1.8.3中(2013年4月22日):
“git submodule update”,当递归到子子模块时,没有累积前缀路径。
因此升级到最新的git版本可以解决这个问题。
此处,OP Thomas Moulard中的the comments提到了一种可能的解决方案(最新的git 1.8.3,2013年4月22日):
$ git submodule deinit -f .
正在发挥作用! 然后我可以运行git submodule init
并修复路径
如果(de)初始化步骤(.git/modules
)
它不会处理在add
文件中记录子模块网址的“.gitmodules
”步骤:您仍然需要在该文件中手动删除它。
答案 1 :(得分:1)
我将其工作副本移到其他地方后成功修复了以下内容:
gitdir:
档案中的superproject/path/to/submodule/.git
路径worktree=
档案中的superproject/.git/modules/path/to/submodule/config
路径我不知道为什么git在那里使用绝对路径!
(在git 2.0.1.563上测试)