這時可以用子模組 submodule,方便管理和增加可讀性。
如上圖,點擊 submodule 後會跳轉至對應的 Github Repo。
前情提要:
有兩個已經在 Github 上的 repository A、B 。
現在要再新創一個 repo(父模組),並以 submodule 的方式連接此兩個 repo。
step 1. 於本地端,開一個新的空資料夾,並初始化 git。
step 2. 建立子模組關係。
在 Git Bash 中輸入以下指令。(這個指令包含 git clone A_repo。)
<remote repository>
:子模組的 URL。<local path>
:本地端中,子模組相對於父模組的路徑位置。這個 local path 理解成在當前資料夾中「新增資料夾的名字」就可以了。
可參考 step 4. 的圖片,這個名字也會是 github 上 submodule 的名稱前綴。
step 3. 回到資料夾中確認有子模組資料夾和一個 .gitmodules
。
step 4.將 parent module 推送到 GitHub 上。
submodule 紀錄的是 commit 版本,在 @
後方的就是版本的流水碼。
submodule 更新後,paremnt module 導向的仍是過去特定提交紀錄的版本。
這個章節是在說明,如何更新 parent module 裡導向 submodule 的版本。
移至 parent module 資料夾層級 ( root folder )。
移至 submodules 資料夾層級。
<branch name>
切換成要提取的分支名稱。