常用工具git和maven

GIT

工作目录

本地库

工作区 -> add -> 暂存区 -> commit -> 本地库

远程库:团队内协作

Amaster:创建本地库 -> push -> 远程库

Bworker:远程库 -> clone -> 本地库 -> 加入团队+push -> 远程库

Amaster:远程库 -> pull -> 本地库

远程库:跨团队协作

Amaster:创建本地库 -> push -> 远程库A

Bmaster:远程库A -> fork -> 远程库B -> clone -> 本地库 -> push -> 远程库B -> pull request+审核+merge -> 远程库A

Amaster:远程库 -> pull -> 本地库

具体操作

本地库

本地文件创建或修改会放到工作区

创建本地库

git config --global user.name "xx"
git config --global user.email "xx.."
git init

上传到本地库

git add xxx
git commit -m "..." xxx

查看工作区和暂存区状态

git status

untracked files 在工作区的文件
changes to be committed 在暂存区的文件

查看本地库操作记录

git log  // 从最近操作到最远操作
// 空格下一页,b上一页

git log --pretty=oneline
git log --oneline
git reflog //多了HEAD@{数字} =》 指针回退到当前版本的步数

前进或回退版本

// 索引号:git reflog 开头的7个数字
git reset --hard 索引  // 移动本地库指针,重置工作区、暂存区
git reset --mixed 索引 // 移动本地库指针,重置暂存区
git reset --soft 索引  // 移动本地库指针

找回文件

// 暂存区
git reset --hard HEAD
// 本地库
git reset --hard 对应版本

对比文件

// 工作区与暂存区
git diff 文件[不写比较全部]
// 暂存区与特定本地库
git diff 索引 文件

分支

查看分支

git fetch --all
git branch -a

创建分支

git branch 分支名

切换分支

git checkout -b 分支名 origin/分支名

合并分支

// 1.切换到主线(分支)
git checkout master
// 2.合并(master)
git merge 分支名
// 3.解决冲突 (master|MERGING)
cat文件名并修改
git add 文件名
git commit -m ""          // 不需要带文件名

远程库

创建远程库并起别名

git remote add 远程库别名 https://....

查看别名

git remote -v

push(前pull解决冲突+add+commit再push)

// 同一个项目git
git push 远程库别名 本地库的分支名 

// 不同的项目(先pull再push)
git pull 远程库别名 远程库的分支名 --allow-unrelated-histories
git push -u 远程库别名 远程库的分支名 -f

clone

git clone https://...

//初始化本地库+克隆远程库+创建远程库别名(origin)

pull = fetch + merge

// 1
git fetch 远程库别名 远程库分支名 // 工作区内容没变

git checkout 远程库别名/远程库分支名 // 查看文件是否正确
git checkout master 

git merge 远程库别名/远程库分支名

// 2
git pull 远程库别名 远程库分支名

免密

cd ~
ssh-keygen -t rsa -C 邮箱名  // 将id_rsa.pub内容复制到对应网页
git remote add xxx git@...

IDEA集成

创建本地库

VCS - import VCS Repository - Greate Git Repository

提交到本地库

文件右击 - Git - add/commit

查看记录

Version Control - Console/Log

关联不同项目

git pull 远程库别名 远程库的分支名 --allow-unrelated-histories
git push -u 远程库别名 远程库的分支名 -f

push

文件右击 - Git - Repository - push

clone

File - NEW - Project from Version Control - Git

MAVEN

全局配置

<localRepository>具体本地仓库位置</localRepository>

<mirror> 
    <!-- 指定镜像ID(可自己改名) -->
    <id>nexus-aliyun</id> 
    <!-- 匹配中央仓库(阿里云的仓库名称,不可以自己起名,必须这么写)-->
    <mirrorOf>central</mirrorOf>
    <!-- 指定镜像名称(可自己改名)  -->   
    <name>Nexus aliyun</name> 
    <!-- 指定镜像路径(镜像地址) -->
    <url>http://maven.aliyun.com/nexus/content/groups/public</url> 
</mirror>

<profile>
    <!-- settings.xml中的id不能随便起的 -->
    <!-- 告诉maven我们用jdk1.8 -->
    <id>jdk-1.8</id>
    <!-- 开启JDK的使用 -->
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
    </activation>
    <properties>
        <!-- 配置编译器信息 -->
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
    </properties>
</profile>

继承

父工程

<groupId>org.example</groupId>
<artifactId>test_java_web</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
        <mybatiesVersion>3.5.4</mybatiesVersion>
    </properties>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatiesVersion}</version>
            <scope>import</scope>  <!-- 无论子工程是否指定版本都用父类的 -->
        </dependency>
    </dependencies>
</dependencyManagement>

子工程

<parent>
    <groupId>org.example</groupId>
    <artifactId>test_java_web</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>...</relativePath>
</parent>
<dependencies>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
    </dependency>
</dependencies>

聚合

父工程

<?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>org.example</groupId>
    <artifactId>testMaven</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <!--告诉编译器父模块不用打包-->
    <packaging>pom</packaging>

    <!--定义子模块-->
    <modules>
        <module>childProject</module>
    </modules>

    <!--定义子模块可能需要使用jar包的版本-->
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <sprint.version>6.1.10</sprint.version>
        <kafka.version>3.5.2</kafka.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${sprint.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.kafka</groupId>
                <artifactId>kafka_2.13</artifactId>
                <version>${kafka.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

子工程

<?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>

    <!--指明父模块-->
    <parent>
        <groupId>org.example</groupId>
        <artifactId>testMaven</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>childProject</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <!--使用父模块定义好的jar包版本-->
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
    </dependencies>
</project>

局部配置-插件

  • 资源打包
  • JDK配置
<!-- 配置maven的编译插件 --> 
<build>
    
    <resources>
        <!--资源打包配置 -->
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    
    <plugins>
        <!--JDK编译插件 -->
        <plugin>
            <!--插件坐标 -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <!-- -->
            <configuration>
                <!-- 源代码使用JDK版本-->
                <source>1.7</source>
                <!-- 源代码编译为class文件的版本,要保持跟上面版本一致-->
                <target>1.7</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        
        <!-- war项目:配置Tomcat插件(运行点maven-tomcat7:run) -->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <!-- 配置Tomcat监听端口 -->
                <port>8080</port>
                <!-- 配置项目的访问路径(Application Context) -->
                <path>/</path>
            </configuration>
        </plugin>
    </plugins>
</build>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值