2012-09-27 75 views
1

我知道这个问题已被打死。但是我仍然不清楚为什么我的子模块试图引用我的超级项目中的提交。我有一个项目,其中有一些子模块,其中一些参考我想贡献的github存储库。更新模块后,我拉模块的变化:如何正确更新git子模块?

 
[[email protected] puppet]$ cd modules/ganglia 
[[email protected] ganglia]$ git branch 
* (no branch) 
    master 
[[email protected] ganglia]$ git pull origin master 
remote: Counting objects: 8, done. 
remote: Compressing objects: 100% (4/4), done. 
remote: Total 6 (delta 4), reused 4 (delta 2) 
Unpacking objects: 100% (6/6), done. 
From https://github.com/andyshinn/puppet-ganglia 
* branch   master  -> FETCH_HEAD 
Merge made by recursive. 
README | 1 + 
1 files changed, 1 insertions(+), 0 deletions(-) 

现在我想更新上层项目的参考模块:

 
[[email protected] ganglia]$ cd ../.. 
[[email protected] puppet]$ git add modules/ganglia 
[[email protected] puppet]$ git commit -m 'updated ganglia module' 
[ganglia c172591] updated ganglia module 
1 files changed, 1 insertions(+), 1 deletions(-) 

我目前工作的神经节的分支,所以我把它推到我的原点(即2个differen't网址):

 
[[email protected] puppet]$ git push origin ganglia 
Counting objects: 8, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (6/6), done. 
Writing objects: 100% (6/6), 616 bytes, done. 
Total 6 (delta 4), reused 0 (delta 0) 
To [email protected]:andyshinn/puppet.git 
    1876698..c172591 ganglia -> ganglia 
Counting objects: 5, done. 
Delta compression using up to 2 threads. 
Compressing objects: 100% (3/3), done. 
Writing objects: 100% (3/3), 323 bytes, done. 
Total 3 (delta 2), reused 0 (delta 0) 
remote: From /var/lib/puppet/repo 
remote: dcd1fcc..c172591 ganglia -> origin/ganglia 
remote: From https://github.com/andyshinn/puppet-ganglia 
remote: a0c4e21..975c92f master  -> origin/master 
remote: fatal: reference is not a tree: c5defdeae006c7b87058cc5c79aef60087b63a6b 
remote: Unable to checkout 'c5defdeae006c7b87058cc5c79aef60087b63a6b' in submodule path 'modules/ganglia' 
remote: Updating existing environment ganglia 
To [email protected]:repo 
    dcd1fcc..c172591 ganglia -> ganglia 

的遥控器有一个后收到脚本在不同的文件夹结账分支机构和运行git submodule update --init每个。如果我手动连接到原始回购,我可以验证问题:

 
-bash-4.1$ git pull 
Already up-to-date. 
-bash-4.1$ git submodule update --init 
fatal: reference is not a tree: c5defdeae006c7b87058cc5c79aef60087b63a6b 
Unable to checkout 'c5defdeae006c7b87058cc5c79aef60087b63a6b' in submodule path 'modules/ganglia' 

我在做什么错在这里?

回答

0

当你完成拉动时,你并不在分支上。 HEAD必须指向你想要的位置。更新你的子模块的正确方法是

git checkout master 
git push origin master 

现在当前提交指向您希望它是。一旦你这样做,你可以在超级项目中添加子模块更改,添加,提交和推送。

另一种方法是使其中的子模块当前的HEAD是分支或标签,并推动这一高达:

git tag interesting HEAD 
git push origin interesting 
cd ../.. 
git add submodule/path 
git commit -m "updated my submodule" 
git push 
+0

我怎样才能做到这一点时,该模块在外部更新?我正努力从其他地方的子模块的外部结账中掌握。超级项目包含子模块的只读URL。 –

+0

我能够在外部更新回购,然后为超级项目内的子模块执行'git checkout master'和'git pull origin master',然后进行提交。它看起来像我缺少的步骤是将子模块附加到分支,然后提交。感谢您帮助我理解这一点! –

+0

注意在包含repo上执行时'git submodule'的输出。您不需要位于子模块的分支中。顶级回购将子模块的指针视为子模块中指向的任何“HEAD”。这可能是无头的(就像在签出标签后)。没有“将子模块附加到分支”的概念。子模块的当前提交是当您执行阶段并随后执行时,顶级回购看到的工作树中的内容。 –