2016-07-15 77 views
0

混帳子模塊更新我克隆一個Git倉庫,mainrepo,其中有一個子模塊submodule1。當我嘗試從submodule1獲得最新更新:--remote不起作用

$ cd mainrepo 

$ git submodule add [email protected]:myaccount/submodule1.git 

$ git submodule update --remote submodule1 
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>] 
    or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...] 
    or: git submodule [--quiet] init [--] [<path>...] 
    or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...] 
    or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] 
    or: git submodule [--quiet] foreach [--recursive] <command> 
    or: git submodule [--quiet] sync [--] [<path>...] 

$ git submodule update --remote 
Usage: git submodule [--quiet] add [-b branch] [--reference <repository>] [--] <repository> [<path>] 
    or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...] 
    or: git submodule [--quiet] init [--] [<path>...] 
    or: git submodule [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...] 
    or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...] 
    or: git submodule [--quiet] foreach [--recursive] <command> 
    or: git submodule [--quiet] sync [--] [<path>...] 

我相信,我曾經嘗試更新submodules這樣,文檔說,也這樣做,但我不明白爲什麼這是行不通的。

但是,如果我做一個獲取並直接在submodule合併,它就會被更新到最新的版本庫提交我所想要的:

$ cd submodule1 

$ git fetch && git merge master 

爲什麼沒有submodule update --remote submodule1命令?

也許這可以幫助:

$ vim mainrepo/.git/config 
[core] 
     repositoryformatversion = 0 
     filemode = true 
     bare = false 
     logallrefupdates = true 
[remote "origin"] 
     fetch = +refs/heads/*:refs/remotes/origin/* 
     url = [email protected]:myaccount/mainrepo.git 
[branch "master"] 
     remote = origin 
     merge = refs/heads/master 
[submodule "local/src/utils"] 
     url = [email protected]:myaccount/submodule1.git 

$ vim .gitmodules 
[submodule "submodule1"] 
     path = submodule1 
     url = [email protected]:myaccount/submodule1.git 
+2

什麼版本的git('git --version')? – larsks

+0

該計算機上的廢話git版本是1.7.1 ...更新遠程子模塊在我的個人電腦上工作,其中git版本更新爲2.9.0。 – kaligne

回答

1

我會建議你閱讀從git的子模塊速成班:https://git-scm.com/book/en/v2/Git-Tools-Submodules

我的猜測是,既然你已經克隆的資源庫有一個子模塊(檢查.gitmodules在回購的根!)你不應該再次git submodule add它。

克隆庫,然後運行git submodule update --recursive就足夠了!

另外,git clone --recurse-submodules做這個自動爲您。