2016-04-29 38 views
0

TLDR:我可以檢查分支庫是否是git子模塊的分支?現在它似乎只是檢查父回購的分支機構,即使它與我最近提交的所有分叉回購的頭部分離。子模塊分揀版本庫獲取父版本庫的分支


有一個開放源碼庫,我不管理稱爲TheLibrary我添加的git的子模塊。然後我需要修改庫並將其用作git子模塊,所以我在github上分叉它,添加了一個新分支modifications並在那裏進行修改。然後,我更新了我的項目的.gitmodules文件包含我的分叉圖書館的網址,像這樣:

[submodule "libs/TheLibrary"] 
    path = libs/TheLibrary 
    url = https://github.com/myUsername/TheLibrary.git 
    branch = modifications 

然後我做了在終端git submodule sync,這給了這樣的結果:

Synchronizing submodule url for 'libs/TheLibrary' 

然後我就去到libs/TheLibrary目錄在終端上,當我做了git fetch它給了我從父回購(主,功能/ FeatureA)的分支。但是,我的分叉存儲庫應該只有這些分支:(主,修改)。

當我做git remote -v,它給了這樣的結果:

origin https://github.com/myUsername/TheLibrary.git (fetch) 
origin https://github.com/myUsername/TheLibrary.git (push) 

當我做git branch,它有這個:

* (HEAD detached at a1b2c3def) 
feature/featureA 
master 

但是,功能/ featureA只是一個拉請求我做了父庫。我分叉的存儲庫應該有我添加的modifications分支。

當我做git log時,它顯示了所有最近從modifications分支提交的提交。

如何查看modifications分支,以便我可以繼續將更改添加到分叉庫中,並將它們推送到遠程回購?目的是希望它仍能夠將來自父回購的更新合併到我們自己的更改中。這甚至可能嗎?謝謝!

回答

0

TLDR:我無法更新現有模塊以使其工作。我不得不與-b標誌運行此命令,它的工作: git submodule add -b modifications https://github.com/myUsername/TheLibrary.git

因此,修改現有的子模塊手動似乎沒有工作,甚至當我刪除整個庫文件夾(libs/TheLibrary),並回顧git submodule initgit submodule update(重新克隆它)。

但是,當我這樣做:

git submodule add -b modifications https://github.com/myUsername/TheLibrary.git

它把它在當前文件夾中的錯誤(我想我應該把正確的路徑作爲最後一個參數),但是當我在那裏去了看它是否檢查了右支(我做git status)它說:

On branch modifications 
Your branch is up-to-date with 'origin/modifications'. 
nothing to commit, working directory clean 

這意味着它的工作!良好的措施,我確實git branch,看它是否有正確的分支:

master 
* modifications 

,它做到了!所以我認爲它總是需要以這種方式完成,使用帶有-b標誌的命令,而不是我嘗試手動更新子模塊的方式。


注意:它的工作即使之後,加入這.gitmodules

[submodule "TheLibrary"] 
     path = TheLibrary 
     url = https://github.com/TheLibrary/TheLibrary.git 
     branch = modifications 

即使它是完全一樣的東西我以前(除了不同的路徑)中輸入相同,它以前沒有工作。運行命令時可能會出現其他一些幕後的事情,我想手動修改這些文件是不夠的。


注2:當我終於得到了正確的文件夾中,我得到這個混帳錯誤:

A git directory for 'libs/TheLibrary' is found locally with remote(s): 
    origin https://github.com/myUsername/TheLibrary.git 
If you want to reuse this local git directory instead of cloning again from 
    https://github.com/myUsername/TheLibrary.git 
use the '--force' option. If the local git directory is not the correct repo 
or you are unsure what this means choose another name with the '--name' option. 

所以我跑這個命令與--force選項,並驗證了它的工作:

git submodule add --force -b modifications https://github.com/myUsername/TheLibrary.git