2011-05-21 110 views
6

如果我添加一個當前不存在的子模塊,則不會將子模塊信息添加到.git/config爲什麼添加現有的回購作爲子模塊修改.git/config?

$ mkdir testing 
$ cd testing 
$ git init 
$ git submodule add [email protected]:submodule.git 
$ cat .git/config 
[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
    ignorecase = true 

不過,如果我補充一點,目前存在的一個子模塊回購,該URL添加到.git/config

$ mkdir testing 
$ cd testing 
$ git init 
$ git clone [email protected]:submodule.git 
$ git submodule add [email protected]:submodule.git 
$ cat .git/config 
[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
    ignorecase = true 
[submodule "submodule"] 
    url = [email protected]:submodule.git 

我都會以爲,在這兩種情況下,git submodule add將只能修改.gitmodules ,並且git submodule init本來會更新該項目的.git/config

爲什麼.git/config在第二種情況下被修改,但不是第一種?有人可以解釋這種行爲的理性嗎?

回答

4

這看起來很奇怪。這種行爲被引入in this commit

commit c2f939170c65173076bbd752bb3c764536b3b09b 
Author: Mark Levedahl <[email protected]> 
Date: Wed Jul 9 21:05:41 2008 -0400 

    git-submodule - register submodule URL if adding in place 

    When adding a new submodule in place, meaning the user created the 
    submodule as a git repo in the superproject's tree first, we don't go 
    through "git submodule init" to register the module. Thus, the 
    submodule's origin repository URL is not stored in .git/config, and no 
    subsequent submodule operation will ever do so. In this case, assume the 
    URL the user supplies to "submodule add" is the one that should be 
    registered, and do so. 

    Signed-off-by: Mark Levedahl <[email protected]> 
    Signed-off-by: Junio C Hamano <[email protected]> 

更新:你指出了低於我原來此提交信息的解釋並沒有任何意義的意見,所以我已刪除的文字現在以避免對他人的困惑。

如在下面的評論中提到,cdwilson發佈到git的郵件列表來問這個矛盾,並因此延斯·萊曼正在努力解決這個問題 - 該線程可以在這裏找到:

+0

馬克,感謝您的指針指向提交(至少它表明這種行爲是故意的)。但是,當您說「在子模塊更新之前不克隆」,我仍然感到困惑。在上面的第一種情況下,'git submodule add [email protected]:submodule.git'實際上將'submodule.git'克隆到超級項目中。在上面的示例中,我運行的唯一子模塊命令是'git submodule add',在這兩種情況下,我都在我的超級項目中使用了克隆的submodule.git。唯一的區別是'.git/config'事後的樣子,case#1也需要'git submodule init'來註冊。 – cdwilson 2011-05-22 16:37:26

+0

如果在第一種情況下'git submodule add'在註冊子模塊('git submodule init')和更新('git submodule update')之前沒有克隆存儲庫,那麼這種行爲對我來說是有意義的。但是,由於上面的case#1確實克隆了'submodule.git',並且需要'git submodule init'來註冊,所以我希望情況#2也需要'git submodule init'來執行註冊。我確信這裏有一些我錯過的東西,但現在我不明白爲什麼會有差異。 – cdwilson 2011-05-22 16:51:15

+0

@cdwilson:好的一點是,我誤解了'git submodule add'在我急於回答問題時的行爲。我會糾正我的答案。你可以在git郵件列表上詢問這個問題的正確答案 - 我懷疑這是一個錯誤,但也許我錯過了一些東西。 – 2011-05-22 17:01:13

相關問題