Git和Maven的子模塊簡單實(shí)踐
當(dāng)一個(gè)產(chǎn)品或者項(xiàng)目由大量獨(dú)立模塊組成時(shí),想要從 Git 挨個(gè)下載下來導(dǎo)入 IDE 查看并不容易,此時(shí)可以結(jié)合使用 Git 和 Maven 的子模塊來處理這種場景。
通過 Git 子模塊可以自動(dòng)批量下載所有關(guān)聯(lián)的項(xiàng)目,通過 Maven 子模塊可以批量導(dǎo)入到 IDE 中,結(jié)合這兩者可以很容易的管理和查看項(xiàng)目。
創(chuàng)建子模塊項(xiàng)目
打開 Git Bash,創(chuàng)建一個(gè)空目錄并進(jìn)入:
$ mkdir erp-submodules $ cd erp-submodules/
把當(dāng)前目錄初始化為 Git 倉庫
$ git init
添加所有子模塊(可以一次輸入多行命令,注意看最后一行命令是否執(zhí)行):
$ git submodule -b master add http://IP/auto-erp/purchase.git git submodule -b master add http://IP/auto-erp/checkup.git git submodule -b master add http://IP/auto-erp/task.git git submodule -b master add http://IP/auto-erp/sale.git Cloning into 'purchase'... remote: Counting objects: 5151, done. remote: Compressing objects: 100% (86/86), done. remote: Total 5151 (delta 49), reused 108 (delta 30) Receiving objects: 100% (5151/5151), 1.12 MiB | 0 bytes/s, done. Resolving deltas: 100% (2269/2269), done. Checking connectivity... done. warning: LF will be replaced by CRLF in .gitmodules. The file will have its original line endings in your working directory.
等待所有項(xiàng)目下載完成。
此時(shí)就創(chuàng)建了所有的子項(xiàng)目,為了方便以 MAVEN 方式導(dǎo)入全部項(xiàng)目,使用子模塊配置。
在當(dāng)前項(xiàng)目下面添加 pom.xml,內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.github.abel533</groupId> <artifactId>erp-modules</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <modules> <!-- 所有子模塊 --> <module>purchase</module> <module>barch</module> <module>checkup</module> <module>task</module> <module>sale</module> <module>packing</module> <module>logistics</module> </modules> </project>
此時(shí)項(xiàng)目已完成,提交本地更改并上傳到 git 服務(wù)器。
# 添加所有 $ git add -all # 提交 $ git commit -m 'first commit' # 添加遠(yuǎn)程倉庫地址 $ git remote add origin 創(chuàng)建好的倉庫地址 # 推送 $ git push origin master
檢出導(dǎo)入項(xiàng)目
剛剛按照上面步驟操作后,本地是可以用了,但是如果其他成員想下載,就需要檢出。
在要檢出的目錄中,打開 git bash,輸入下面的命令檢出項(xiàng)目:
$ git clone --recursive 倉庫地址 # 以下為部分輸出日志 Cloning into 'erp-modules'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (6/6), done. remote: Total 6 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (6/6), done. Checking connectivity... done. Submodule 'ERPcrm' (http://IP/auto-erp/ERPcrm.git) registered for path 'ERPcrm' Submodule 'accountNew' (http://IP/auto-erp/accountNew.git) registered for path 'accountNew' Submodule 'barch' (http://IP/auto-erp/barch.git) registered for path 'barch' Submodule 'checkup' (http://IP/auto-erp/checkup.git) registered for path 'checkup' Submodule 'contract' (http://IP/auto-erp/contract.git) registered for path 'contract' Cloning into 'ERPcrm'... remote: Counting objects: 1651, done. remote: Compressing objects: 100% (274/274), done. remote: Total 1651 (delta 139), reused 447 (delta 70) Receiving objects: 100% (1651/1651), 265.91 KiB | 0 bytes/s, done. Resolving deltas: 100% (494/494), done. Checking connectivity... done. Submodule path 'ERPcrm': checked out '26686570bc1f22627f717830599ac77248014b87' Cloning into 'accountNew'... remote: Counting objects: 1850, done. remote: Compressing objects: 100% (689/689), done. otal 1850 (delta 866), reused 1624 (delta 664) Receiving objects: 100% (1850/1850), 496.70 KiB | 0 bytes/s, done. Resolving deltas: 100% (866/866), done. Checking connectivity... done.
此時(shí)所有子模塊都自動(dòng)下載了,但是所有子模塊都沒有選擇分支,如果不選擇分支會(huì)導(dǎo)致項(xiàng)目混亂,所以下面切換分支,并且更新。
# 進(jìn)入 clone 下來的目錄 $ cd erp-modules/ # 執(zhí)行下面的命令 git submodule foreach <命令> $ git submodule foreach git checkout master && git pull origin master
所有子模塊都切換到了 master 分支并且進(jìn)行了更新??梢詫㈨?xiàng)目導(dǎo)入 IDE 了。
在后續(xù)使用的時(shí)候,要隨時(shí)注意子模塊的分支,防止意外導(dǎo)致的錯(cuò)誤。
利用git submodule foreach <命令>
可以很方便的對(duì)子模塊批量執(zhí)行命令。
刪除 Git 子模塊比較麻煩,可以參考下面地址:
https://gist.github.com/myusuf3/7f645819ded92bda6677
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
- maven利用tomcat插件部署遠(yuǎn)程Linux服務(wù)器的步驟詳解
- android 上傳aar到私有maven服務(wù)器的示例
- maven自動(dòng)部署到遠(yuǎn)程tomcat服務(wù)器的方法
- 淺談maven單元測試設(shè)置代理
- Maven的聚合(多模塊)和Parent繼承
- 批量將現(xiàn)有Jar包上傳到Maven私服
- Maven最佳實(shí)踐之一個(gè)好的parent依賴基礎(chǔ)
- 詳解maven安裝教程以及解決安裝不成功的解決辦法
- 詳解Maven settings.xml配置(指定本地倉庫、阿里云鏡像設(shè)置)
- 在Maven下代理服務(wù)器設(shè)定的方式
相關(guān)文章
Java for循環(huán)性能優(yōu)化實(shí)現(xiàn)解析
這篇文章主要介紹了Java for循環(huán)性能優(yōu)化實(shí)現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01Spring超詳細(xì)講解創(chuàng)建BeanDefinition流程
Spring在初始化過程中,將xml中定義的對(duì)象解析到了BeanDefinition對(duì)象中,我們有必要了解一下BeanDefinition的內(nèi)部結(jié)構(gòu),有助于我們理解Spring的初始化流程2022-06-06java使用ffmpeg實(shí)現(xiàn)上傳視頻的轉(zhuǎn)碼提取視頻的截圖等功能(代碼操作)
這篇文章主要介紹了java使用ffmpeg實(shí)現(xiàn)上傳視頻的轉(zhuǎn)碼,提取視頻的截圖等功能,本文圖文并茂給大家介紹的非常詳細(xì),對(duì)大家的工作或?qū)W習(xí)具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03MyBatis?如何使項(xiàng)目兼容多種數(shù)據(jù)庫的解決方案
要想做兼容多種數(shù)據(jù)庫,那毫無疑問,我們首先得明確我們要兼容哪些數(shù)據(jù)庫,他們的數(shù)據(jù)庫產(chǎn)品名稱是什么,本次我們講解了一套使項(xiàng)目兼容多種數(shù)據(jù)庫的方案,對(duì)MyBatis項(xiàng)目兼容多種數(shù)據(jù)庫操作方法感興趣的朋友一起看看吧2024-05-05java實(shí)現(xiàn)馬踏棋盤算法(騎士周游問題)
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)馬踏棋盤算法,解決騎士周游問題,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02SpringBoot+Eureka實(shí)現(xiàn)微服務(wù)負(fù)載均衡的示例代碼
這篇文章主要介紹了SpringBoot+Eureka實(shí)現(xiàn)微服務(wù)負(fù)載均衡的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11