2012-08-31 133 views
15

我想添加一個已經存在的子模塊(不同的git遠程存儲庫)。由於我之前沒有搜索過如何正確執行該操作,因此我認爲我已經搞亂了我的存儲庫,我需要一些幫助來重新修復它。添加一個無法從索引中刪除的子模塊

我已經刪除了.gitmodules和.git/config有關我想要刪除的子模塊的所有相關部分。我還驗證了我的.git /目錄下沒有模塊目錄。

然而,當我運行命令git rm --cached path_to_submodule,顯示以下信息:

 
fatal: pathspec 'path_to_submodule' did not match any files 

正如前面的命令失敗,當我嘗試用新的定義重新添加同一子模塊,運行命令git submodule add [email protected]:repo.git ,這是所顯示的消息:

 
'repo' already exists in the index 
+0

我正試圖添加一個子模塊,該子模塊與索引中已存在文件的名稱相同。 –

回答

32

的唯一方法可以顯示該消息('repo' already exists in the index)是如果「回購」在索引中仍然存在(參見this chapter on submodule):

$ rm -Rf rack/ 
$ git submodule add [email protected]:schacon/rack.git rack 
'rack' already exists in the index 

You have to unstage the rack directory first. Then you can add the submodule: 

$ git rm -r rack 
$ git submodule add [email protected]:schacon/rack.git rack 

即使「rack」不是一個子模塊,如果存在的話,它可能會妨礙同名的子模塊的聲明。

1

可能發生在文件.gitmodules錯誤,子模塊的文件夾中手動刪除,或別的東西,合併就像Hallileo彗星

  1. 時 - 刪除鏈接的子模塊(與子模塊名全段)

  2. 文件.git\config - 刪除鏈接的子模塊,如前面的步驟

  3. 文件夾.git\modules - 刪除文件夾類似與r相對路徑「問題」 模塊

  4. 保證,子模塊的該文件夾是不是elative路徑不再存在

  5. 則:

    $ git submodule add -f --name <name> <git://path_1.git> <path_2>

    其中:name - 子模塊的名稱爲u希望,可等於你的名字repo; - 子模塊源回購(即 - github等)的路徑, - 子模塊所在文件夾的相對路徑

    這讓您可以在路徑中添加子模塊,或者使用名稱仍然存在於索引中,但不會自然存在。

我沒有發現任何方法來移除這些指數的死鏈接,但被迫

1

時如果輸出增加一個新的子模塊:

'FolderName' already exists in the index 

提示下一個命令

git ls-files --stage 

輸出結果類似於:

160000 d023657a21c1bf05d0eeaac6218eb5cca8520d16 0 FolderName 

然後,刪除的文件夾的索引尖端:

git rm -r --cached FolderName 

嘗試再次添加子模塊

+0

感謝您爲我工作 –

0

'子模塊/ uasdk-CLIB' 已經存在於索引

GIT中RM - [R --cached子模塊/ uasdk-CLIB

git的子模塊加-b中國/發行/ 16.8.0 -f SSH://[email protected]子模塊/ uasdk,CLIB