2013-05-11 89 views
0

在處理子模塊時,我有一個git pull的主要問題。我以爲我開始瞭解他們的原則,但顯然不是...在子模塊中的Git拉將創建另一個子模塊

我創建了一個簡單的git repo Super,並在其中創建了一個子模塊module。我的第一個問題是,當在module(我添加一個文本文件)中進行提交併推送代碼時,我可以看到在github上該文本文件沒有進入子模塊module,但實際上進入了超級項目Super(子模塊甚至不顯示在github中)。因此,當我在Super中執行git pull操作時,最終會在我的repo的本地副本中出現文本文件,這些文件已被我的子模塊推入...我不確定我做錯了什麼。這裏的代碼基本上是:

cd module (a text file "Test" was added to be commited) 
    ~/Super/module [master]: git add -A 
    ~/Super/module [master]: git commit -m 'comment' 
    ~/Super/module [master]: git push 
    cd Super 
    ~/Super [master] : git pull 
    and now the text file "Test" shows up in my Super next to the submodule "module". 

所以這已經是問題,但我可以忍受。我現在進入我的Super並刪除此文本文件並添加對子模塊module所做的更改以重新命名最新的子模塊提交。

(after deleting the text file) 
~/Super [master] : git add -A 
~/Super [master] : git commit -m 'comment 2' 
~/Super [master] : git submodule update 
~/Super [master] : git pull 
~/Super [master] : git push 

我現在走在我的子模塊,做一個git拉

~/Super/module [master]: git pull 

,這創造一個在超級所有內容的副本,並把它的子模塊module。所以如果我在module中做ls,我發現一個嵌套的子模塊module,這是個大問題。

~/Super/module/module [master]: 

所以我基本上有2個問題:

  • 當我把我的子模塊來更新我的子項目會後,我的子模塊拉當副本去上層項目

  • ,它會創建一個嵌套子模塊。

有人能告訴我我做錯了什麼嗎?我很抱歉,如果這看起來很明顯,但我一直在這個問題上停留,這是非常令人沮喪的。

我從超級添加的.gitmodules文件和的.git /配置:

.gitmodules:

[submodule "module"] 
path = module 
url = [email protected]:titocazou/Super.git 

的.git /配置:

[core] 
repositoryformatversion = 0 
filemode = true 
bare = false 
logallrefupdates = true 
[remote "origin"] 
url = [email protected]:titocazou/Super.git 
fetch = +refs/heads/*:refs/remotes/origin/* 
[branch "master"] 
remote = origin 
merge = refs/heads/master 
[submodule "module"] 
url = [email protected]:titocazou/Super.git 
+0

如果你可以添加Super repo中'.gitmodules'文件的內容和''的內容,這將有所幫助。在超級和模塊回購中的git/config。 – Amber 2013-05-11 01:55:43

回答

0

這聽起來我就像你可能爲你的子模塊設置了錯誤的遠程路徑一樣,所以你的子模塊實際上是指向一個與你的父庫共享的遠程。 (基本上,你已經在自己的內部複製了你的倉庫。)

檢查.gitmodules的內容以查看你的子模塊實際指向什麼遠程路徑來推動和拉動,並確保它與你的路徑不一樣父庫是推動和拉動。

+0

非常感謝琥珀關於你的快速回答!我曾經想過,它可能來自.gitmodules網址(因爲超級模塊和模塊網址匹配),但是我應該將它們改爲? (我已將.gitmodules和.git/config文件添加到我的問題中) – titocazou 2013-05-11 03:10:14

+0

子模塊被設計爲一個完全獨立的存儲庫(只需嵌入在不同存儲庫的目錄樹中)。您希望爲子模塊創建第二個存儲庫並將子模塊指向該子模塊。但是,另一個問題是......您想要首先使用子模塊? – Amber 2013-05-11 03:43:22