iT邦幫忙

0

Git Submodule 使用方式 with Coinlifee

git
  • 分享至 

  • xImage
  •  

新增 Submodule
打開 Terminal 進入欲新增 Submodule 的專案資料夾下,輸入下列指令:

git submodule add {git_url_path} {module_name}

範例:

git submodule add http://192.168.0.100/tools/common.git common
完成後,輸入 git status,會發現多了二個檔案需要 commit

build.gradle 設定
開啟 build.gradle 檔案,加入 project

implementation project(':common')
settings.gradle 設定
開啟 settings.gradle 檔案,加入下列設定

include ':common'
Submodule build.gradle 設定
如果遇到了 Submodule package not found 的問題,要將 Submodule 的build.gradle 修改設定

修改前:

plugins {
id 'java'
id 'org.springframework.boot' version "${VERSION_SPRING_BOOT}"
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
}
修改後:

將 plugins 設定移出改為使用 apply plugin,並加入 bootJar & jar 的設定

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
plugins {
id 'java'
}
bootJar {
enabled = false
}
jar {
enabled = true
}
移除 Submodule
想解除 Submodule 要怎麼做呢?需要將 Submodule 資料夾與 .gitmodules 檔案刪除,也可以輸入下列指令:

git rm --cached common
rm common
rm .gitmodules
然後開啟 .git/config 檔案,將 submodule 整段設定移除,並存檔,整段文字長的會像下列這樣:

//下面這段移除後存檔
[submodule "common"]
url = http://192.168.0.100/tools/common.git
active = true
Submodule 自動更新
當 Submodule master branch 有更動,引用的專案會自動更新,只要將新的程式碼 pull 下來就可以囉。

Git Clone Project with Submodule
在下 git clone 的指令將 project 抓下來時,並不會把 Submodule 一併取得,需使用 --recursive

git clone --recursive http://192.168.0.100/tools/common.git
如果發現 Submodule 資料夾是空的,可以利用下列指令進行 update

git submodule init
git submodule update --recursive
有安裝 Sourcetree 就不用擔心這個問題, Submodule 會幫你抓下來的。


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言