2012-02-23 109 views
8

所以我幾天前開始使用Git。 (晚會很晚 - 不要罵:))。真正開始習慣基本的命令,想法和工作流程。然而,submodules真的讓我的大腦乘坐。我正在嘗試向FuelPHPGitHub提供代碼,我可以使用一些指導和提示。Git子模塊工作流程建議

我在終端運行以下命令:

//1: clone the repository from Fuel's github. 
git clone git://github.com/fuel/fuel.git 

//2: move into the main fuel directory 
cd fuel 

//3: initilize the submodules (populate .git/config with submodule data) 
git submodule init 

//4: download the submodules... 
git submodule update 

//5: move into the core directory (which is a submodule). 
cd fuel/core 

//6: change branch from (*no branch) to 1.1/develop 
git checkout 1.1/develop 

//7: open random file in text editor + make some small change (i.e. typo) + save file. 
sudo gedit classes/autoloader.php 

//8: add this file to the staging area. 
git add classes/autoloader.php 

//9: commit this file under 1.1develop branch. 
git commit -m "im committing a submodule" 

//10: push the new commit to MY (not fuel's) github repo (yes i've renamed the repo). 
git push [email protected]:jordanarseno/fuel-core.git 

//11: changes are reflected on github, looks good. 

//12: back way out to fuel again. time to push the submodule commit separately. 
cd ../../ 

//13: add the fuel/core submodule to the staging area. 
git add fuel/core 

//14: commit the submodule change. 
git commit -m "submodule pushed. pushing super now." 

//15: push the commit to MY (not fuel's) github repo. 
git push [email protected]:jordanarseno/fuel.git 

具體來說,我的問題是:

  1. 這是與子模塊工作的正確的工作流程?你會做什麼?
  2. 爲什麼git將子模塊中的1.1/develop分支拉下來,但默認情況下設置爲*no branch?我可以修改這種行爲嗎?
  3. Fuel子模塊的哪個部分告訴git拉1.1 /開發? 其他分支(1.1/master,1.0/develop等)。
  4. 爲什麼我們不能在第11步中稱呼它?子模塊推動正常工作。之後我推超,因爲手冊tells me it's a good idea。事實上,前往GitHub並看着我的超級,提交了一個提交。然而,它似乎只是Fuel的超級參考,而不是我的超級參考。它不應該鏈接到我的回購,而不是他們的?
  5. 運行在超顯示cat .git/config

隨着所有的子模塊...

[remote "origin"] 
fetch = +refs/heads/*:refs/remotes/origin/* 
url = git://github.com/fuel/fuel.git` 

核心子模塊運行cat .git config顯示:

[remote "origin"] 
fetch = +refs/heads/*:refs/remotes/origin/* 
url = git://github.com/fuel/core.git 

難道是明智的更改這些網址爲我自己在GitHub上的回購?無論如何,燃料否認推動。如果我執行子模塊更新,它們是否會被覆蓋?

我也在Fuel's Forums上問過這個問題,但這是更常見的問題,這裏還有更多的Gitters ......謝謝!

回答

10
  1. 是的,在「true nature of submodules

  2. 一個git子模塊的引用到一個特定的提交(SHA1),而不是一個分支解釋,所以你總是在分離模式中的第一(這與只讀用法兼容)。
    換句話說,git submodule update檢出了一個特定的提交,而不是分支的提示。
    .gitmodule文件將包含您的子模塊回購的參考。並且特定的SHA1將作爲特殊提交(模式160000)記錄在父回購中。當'git submodule add'是一個新的子模塊時,它記錄當前檢出其他回購的SHA1(無論其分支)。
    如果您想進行更改,那麼您必須簽出該子模塊回購(現有分支或新的:在這兩種情況下,您將推回任何新的變化回到該子模塊的遠程回購)分支。
    另一種方法是git slave

  3. 見2. git branch列出的其他分支(ES)是當地的一個存在於你的子模塊的回購協議,其中包括一個地方分支每個tracking branch,如果你在一個點上做了git pull

  4. 由於父級仍然引用子模塊的初始SHA1。
    但是由於您已對其進行了修改,因此需要更新SHA1。
    請記住,子模塊本身是一個git回購......絕對不會將它用作子模塊。因此有必要在回購協議中記錄該回購協議的新狀態(唯一一個跟蹤其子模塊的狀態)。
    你的第一個git推動完全是內部操作的子模塊回購(根本沒有看到父回購)。
    對於父回購,子模塊回購是一個「黑匣子」,只有一個遠程地址和一個SHA1。無論在子模塊內執行了什麼操作,對父代都沒有影響,只會檢測子模塊樹的SHA1的變化。

  5. 使用forks可能有助於
    請參閱 「Changing remote repository for a git submodule」 更新你的子模塊的遠程URL。

+0

非常感謝!優秀的帖子在其他線程。重新:2;如何找到子模塊引用的特定提交?您說過「必須在該子模塊回購中檢出分支」 - 它必須是*現有*分支嗎?我可以創造我自己的,並從那裏工作耶?回覆:3;在子模塊中運行'git branch'會返回'* no branch'等。這些'別人'從哪裏來,是我想知道的。回覆:4;運行第二個git push應該已經完成​​了這個..你說它失敗了嗎?回覆:5;是的,這是主意。叉,然後更改網址。 git submodule update會覆蓋嗎? – 2012-02-23 12:08:39

+0

@JordanArsenault:我編輯了我的答案以解決您的評論:http://stackoverflow.com/posts/9411932/revisions – VonC 2012-02-23 13:44:33