Git和Maven的子模塊簡單實踐
當(dāng)一個產(chǎn)品或者項目由大量獨立模塊組成時,想要從 Git 挨個下載下來導(dǎo)入 IDE 查看并不容易,此時可以結(jié)合使用 Git 和 Maven 的子模塊來處理這種場景。
通過 Git 子模塊可以自動批量下載所有關(guān)聯(lián)的項目,通過 Maven 子模塊可以批量導(dǎo)入到 IDE 中,結(jié)合這兩者可以很容易的管理和查看項目。
創(chuàng)建子模塊項目
打開 Git Bash,創(chuàng)建一個空目錄并進入:
$ 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.
等待所有項目下載完成。
此時就創(chuàng)建了所有的子項目,為了方便以 MAVEN 方式導(dǎo)入全部項目,使用子模塊配置。
在當(dā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>
此時項目已完成,提交本地更改并上傳到 git 服務(wù)器。
# 添加所有 $ git add -all # 提交 $ git commit -m 'first commit' # 添加遠(yuǎn)程倉庫地址 $ git remote add origin 創(chuàng)建好的倉庫地址 # 推送 $ git push origin master
檢出導(dǎo)入項目
剛剛按照上面步驟操作后,本地是可以用了,但是如果其他成員想下載,就需要檢出。
在要檢出的目錄中,打開 git bash,輸入下面的命令檢出項目:
$ 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.
此時所有子模塊都自動下載了,但是所有子模塊都沒有選擇分支,如果不選擇分支會導(dǎo)致項目混亂,所以下面切換分支,并且更新。
# 進入 clone 下來的目錄 $ cd erp-modules/ # 執(zhí)行下面的命令 git submodule foreach <命令> $ git submodule foreach git checkout master && git pull origin master
所有子模塊都切換到了 master 分支并且進行了更新??梢詫㈨椖繉?dǎo)入 IDE 了。
在后續(xù)使用的時候,要隨時注意子模塊的分支,防止意外導(dǎo)致的錯誤。
利用git submodule foreach <命令> 可以很方便的對子模塊批量執(zhí)行命令。
刪除 Git 子模塊比較麻煩,可以參考下面地址:
https://gist.github.com/myusuf3/7f645819ded92bda6677
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
相關(guān)文章
Java for循環(huán)性能優(yōu)化實現(xiàn)解析
這篇文章主要介紹了Java for循環(huán)性能優(yōu)化實現(xiàn)解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-01-01
Spring超詳細(xì)講解創(chuàng)建BeanDefinition流程
Spring在初始化過程中,將xml中定義的對象解析到了BeanDefinition對象中,我們有必要了解一下BeanDefinition的內(nèi)部結(jié)構(gòu),有助于我們理解Spring的初始化流程2022-06-06
java使用ffmpeg實現(xiàn)上傳視頻的轉(zhuǎn)碼提取視頻的截圖等功能(代碼操作)
這篇文章主要介紹了java使用ffmpeg實現(xiàn)上傳視頻的轉(zhuǎn)碼,提取視頻的截圖等功能,本文圖文并茂給大家介紹的非常詳細(xì),對大家的工作或?qū)W習(xí)具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03
MyBatis?如何使項目兼容多種數(shù)據(jù)庫的解決方案
要想做兼容多種數(shù)據(jù)庫,那毫無疑問,我們首先得明確我們要兼容哪些數(shù)據(jù)庫,他們的數(shù)據(jù)庫產(chǎn)品名稱是什么,本次我們講解了一套使項目兼容多種數(shù)據(jù)庫的方案,對MyBatis項目兼容多種數(shù)據(jù)庫操作方法感興趣的朋友一起看看吧2024-05-05
SpringBoot+Eureka實現(xiàn)微服務(wù)負(fù)載均衡的示例代碼
這篇文章主要介紹了SpringBoot+Eureka實現(xiàn)微服務(wù)負(fù)載均衡的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11

