Git和Maven的子模塊簡(jiǎn)單實(shí)踐
當(dāng)一個(gè)產(chǎn)品或者項(xiàng)目由大量獨(dú)立模塊組成時(shí),想要從 Git 挨個(gè)下載下來(lái)導(dǎo)入 IDE 查看并不容易,此時(shí)可以結(jié)合使用 Git 和 Maven 的子模塊來(lái)處理這種場(chǎng)景。
通過(guò) Git 子模塊可以自動(dòng)批量下載所有關(guān)聯(lián)的項(xiàng)目,通過(guò) Maven 子模塊可以批量導(dǎo)入到 IDE 中,結(jié)合這兩者可以很容易的管理和查看項(xiàng)目。
創(chuàng)建子模塊項(xiàng)目
打開(kāi) Git Bash,創(chuàng)建一個(gè)空目錄并進(jìn)入:
$ mkdir erp-submodules $ cd erp-submodules/
把當(dāng)前目錄初始化為 Git 倉(cāng)庫(kù)
$ 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)程倉(cāng)庫(kù)地址 $ git remote add origin 創(chuàng)建好的倉(cāng)庫(kù)地址 # 推送 $ git push origin master
檢出導(dǎo)入項(xiàng)目
剛剛按照上面步驟操作后,本地是可以用了,但是如果其他成員想下載,就需要檢出。
在要檢出的目錄中,打開(kāi) git bash,輸入下面的命令檢出項(xiàng)目:
$ git clone --recursive 倉(cāng)庫(kù)地址 # 以下為部分輸出日志 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)下載了,但是所有子模塊都沒(méi)有選擇分支,如果不選擇分支會(huì)導(dǎo)致項(xiàng)目混亂,所以下面切換分支,并且更新。
# 進(jìn)入 clone 下來(lái)的目錄 $ 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é)
以上就是這篇文章的全部?jī)?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單元測(cè)試設(shè)置代理
- Maven的聚合(多模塊)和Parent繼承
- 批量將現(xiàn)有Jar包上傳到Maven私服
- Maven最佳實(shí)踐之一個(gè)好的parent依賴基礎(chǔ)
- 詳解maven安裝教程以及解決安裝不成功的解決辦法
- 詳解Maven settings.xml配置(指定本地倉(cāng)庫(kù)、阿里云鏡像設(shè)置)
- 在Maven下代理服務(wù)器設(shè)定的方式
相關(guān)文章
Linux系統(tǒng)下搭建Java開(kāi)發(fā)環(huán)境
本文主要是記錄了如何在Linux環(huán)境下一步步安裝JAVA JDK環(huán)境,非常簡(jiǎn)單實(shí)用,有需要的朋友可以參考下2014-10-10
Java集合框架迭代器Iterator實(shí)現(xiàn)原理解析
這篇文章主要介紹了Java集合框架迭代器Iterator實(shí)現(xiàn)原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08
Javaweb mybatis接口開(kāi)發(fā)實(shí)現(xiàn)過(guò)程詳解
這篇文章主要介紹了Javaweb mybatis接口開(kāi)發(fā)實(shí)現(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07
利用JDBC的PrepareStatement打印真實(shí)SQL的方法詳解
PreparedStatement是預(yù)編譯的,對(duì)于批量處理可以大大提高效率. 也叫JDBC存儲(chǔ)過(guò)程,下面這篇文章主要給大家介紹了關(guān)于利用JDBC的PrepareStatement打印真實(shí)SQL的方法,需要的朋友可以參考借鑒,下面來(lái)一起看看吧。2017-07-07

