2016-12-05 359 views
1

我正在第一次使用git子模塊。瞭解如何創建全線分支並將其添加到所有遠程回購站中。使用git submodules創建多個遠程分支

目前我的文件結構如下所示:

-parent_repo 
    | 
    |_ submodule_1 
    |_ submodule_2 
    |_ submodule_3 
    |_ submodule_4 
    |_ submodule_5 
    |_ submodule_6 
    |_ submodule_7 

如果我創建於母公司回購分支:

(master) $ git checkout -b feature/my_feature 
(feature/my_feature) $ git commit -m "created my_feature" 
(feature/my_feature) $ git push -u origin feature/my_feature 

我想創建跨越所有子模塊包括父分支。之後,將所有分支機構推送至每個子模塊及其受尊重的回購站。

嘗試了以下步驟:

$ git submodule foreach -b branch_name 
$ git push --recurse-submodules=on-demand 
$ git submodule foreach "(git checkout branch_name; git pull)&" 

..just失敗。找不到第一個命令。

..和如果我這樣做:

$ git config -f .gitmodules submodule.submodule_1.branch branch_name 
$ git submodule update --remote 

git的回報:

fatal: Needed a single revision 
Unable to find current origin/branch_name revision in submodule path 'submodule_1' 
+0

'git的子模塊的foreach -b branch_name'應該是'git的子模塊的foreach「git的結帳-b branch_name'' –

回答

1

Submodule tips

例如,假設我們要開始一個新的功能或做一個錯誤修正,我們有幾個子模塊正在進行工作。
我們可以很容易藏匿所有的工作在我們所有的子模塊:

$ git submodule foreach 'git stash' 
Entering 'CryptoLibrary' 
No local changes to save 
Entering 'DbConnector' 
Saved working directory and index state WIP on stable: 82d2ad3 Merge from origin/stable 
HEAD is now at 82d2ad3 Merge from origin/stable 

然後,我們可以創建一個新的分支,並切換到它在我們的所有子模塊:

$ git submodule foreach 'git checkout -b featureA' 
Entering 'CryptoLibrary' 
Switched to a new branch 'featureA' 
Entering 'DbConnector' 
Switched to a new branch 'featureA' 

然後,您仍然需要在父回購,創建,提交和推送中創建相同的分支,因爲所有子模塊回購都將發生更改。

但要記住:這些都是不同的分支(即使它們具有相同的名稱),每一個具體到自己的回購協議(無論是父回購或回購子模塊)。

+0

一旦創建和爲您上面提到的檢出分支。哪些工作。您是否熟悉能夠在所有回購協議中「推送-u起源featureA」,而無需進入每個回收站並創建遠程分支。像'$ git submodule foreach'git push -u origin featureA''。 由於子模塊是使用http引用而不是ssh創建的,因此係統會提示輸入憑據。 – Josh

+0

@Josh你可以嘗試在一個子模塊中,並且一次性緩存這些憑據:請參閱http://stackoverflow.com/a/13386417/6309的開頭部分。 – VonC