2017-08-30 167 views
0

我有一個帶有單個子模塊的超級項目。該子模塊完全獨立於超級項目開發,但這不是我的超級項目設置方式。目前,當子模塊的來源得到更新時,如果有人(我)運行git submodule update --recursive --remote,然後將該更新提交給超級項目,則只會更新超級項目。那很愚蠢;我不跟蹤任何版本或提交我的超級項目中子模塊的散列。我想要的是在我的超級項目中擁有子模塊的起源/主人,無論起源/主人是什麼。我只想要同步子模塊,而不是將子模塊提交到我的超級項目中。git子模塊:如何保持子模塊當前不提交到超級項目?

例如,做一個git clone,爲了得到子模塊後,我跑git submodule update --init --recursive並獲得這樣的:

$ git submodule update --init --recursive 
Submodule 'scripts/token' (https://gitserver.company.com/token.git) registered for path 'scripts/token' 
Submodule path 'scripts/token': checked out '93b6bee2031913f563f548883358a65a136bdd88' 

但提交哈希93b6bee2031913f563f548883358a65a136bdd88不是令牌回購的起源/主;那是0f39201818985d21a1f2362ad5b519793bd4f2b6。爲了得到這一點,我已經運行另一個git submodule命令:

$ git submodule update --recursive --remote 
Cloning into '/Users/me/superproject/scripts/token'... 
Submodule path 'scripts/token': checked out '0f39201818985d21a1f2362ad5b519793bd4f2b6' 
$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 

Changes not staged for commit: 
(use "git add <file>..." to update what will be committed) 
(use "git checkout -- <file>..." to discard changes in working directory) 

    modified: scripts/token (new commits) 

沒有,我沒有「新提交」到上層項目;我剛剛同步了一個子模塊。我希望這個工作像一個依賴;我想token>=0.0.1(無論是起源/主),但它似乎是我所擁有的是token=explicit_commit_hash。我不想在我的超級項目中支持版本號或提交子模塊標記的哈希值。

UPDATE:換句話說,如果git status說:「跟上時代的」不當地修改運行git submodule update前,然後git submodule update更新子模塊後,我還是想git status說「上的最新」沒有本地變化。

我在做什麼錯?

回答

0

我能想到的最接近的近似方式是爲你的克隆使用一個別名,一個子模塊更新遠程克隆(surclone或任何你想調用它的東西)。將以下內容添加到您的.gitconfig文件中。由於shell將嘗試解析參數,因此通過git config --global alias.surclone添加它將不起作用。

surclone = "!f() { git clone --recursive ${1} . && git submodule update --remote --recursive --init; }; f" 

您可以擴展命令自動提交(git commit --amend -a -m "Current master version of all submodules"),然後用力將其推送到服務器(git push -f)。這一切都需要添加子模塊的時候,你也可以指定分支它是跟蹤,或以後添加此,例如,.gitmodules

[submodule "SubmoduleA"] 
    path = SubmoduleA 
    url = [email protected]:some/repo.git 
    branch = master 
+0

我正在尋找的是一切都交給了'git的commit'。我不想讓子模塊更新甚至被視爲修改後的代碼。如果'git status'說的是「最新的」,那麼在'git submodule update'更新子模塊之後,我仍然希望'git status'說「最新」而不需要本地修改。 – DrStrangepork