Jgit获取最近一次commit的文件和文件列表

更新时间:2023-05-25 15:20:07 阅读: 评论:0

Jgit获取最近⼀次commit的⽂件和⽂件列表pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0"
反义疑问句的回答xsi="/2001/XMLSchema-instance"
schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xs</groupId>
<artifactId>git_package</artifactId>
<version>1.0</version>
<properties>
spin_lock
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<java.version>1.8</java.version>
&piler.source>1.8</piler.source>
&piler.target>1.8</piler.target>
</properties>
<dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
me too什么意思<version>5.3.8</version>
</dependency>
<dependency>
<groupId&lip.jgit</groupId>
<artifactId&lip.jgit</artifactId>
<version>5.1.3.201810200350-r</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.1.RELEASE</version>
<configuration>
<mainClass>
com.xs.git.JGitTest
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
汉英翻译在线package com.xs.git;
import io.FileUtil;
lip.jgit.api.Git;
八年级英语教学总结lip.s.GitAPIException;
lip.jgit.diff.DiffEntry;
lip.jgit.lib.ObjectId;
lip.jgit.lib.ObjectReader;
lip.jgit.lib.Repository;
lip.jgit.lib.Repository;
lip.jgit.storage.file.FileRepositoryBuilder;
walk.CanonicalTreeParr;
import java.io.File;
import java.io.IOException;快递惊魂
import java.util.ArrayList;
import java.util.List;
/**
* @Author xs
* @Date 2020/7/15 14:19
* @Description ⽤JGit获取提交记录
* 1.将程序放在git项⽬下
*/
public class JGitTest {
public static void main(String[] args)throws IOException, GitAPIException {
System.out.println("com.xs.git_package Start!");
System.out.println();
try(Repository repository =openJGitCookbookRepository()){
//^表⽰前⼏个⽗提交 ^^ 前两次和^前⼀次的对⽐
ObjectId oldHead = solve("HEAD^^^{tree}");
ObjectId head = solve("HEAD^{tree}");
//获取classpath路径 /C:/HRP/HRP/out/production/HRP1/
String classPath = Resource("/").getPath().substring(1);
String baPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();            System.out.println("线程获取:"+baPath);
//获取项⽬路径  //C:\HRP\HRP
File directory =new File("");
String projectPath = CanonicalPath()+"\\";
寓教于乐英文String sourcePath ="";
File toFile =new File("D:/web-config/package");
File txtFile =new File("D:/web-config/");
inthedistance
//不存在则创建⽬录
if(!ists()){
toFile.mkdirs();
}
if(!ists()){
toFile.mkdir();
}
ArrayList arrayList =new ArrayList();
// prepare the two iterators to compute the diff between
try(ObjectReader reader = wObjectReader()){
CanonicalTreeParr oldTreeIter =new CanonicalTreeParr();
<(reader, oldHead);
CanonicalTreeParr newTreeIter =new CanonicalTreeParr();
<(reader, head);
// finally get the list of changed files
国际贸易英语词汇try(Git git =new Git(repository)){
List<DiffEntry> diffs = git.diff()
.tNewTree(newTreeIter)
.tOldTree(oldTreeIter)
耶鲁大学公开课
.call();
for(DiffEntry entry : diffs){
//增加和修改的⽂件进⾏打包,删除的过滤掉
if("DELETE".ChangeType().name())){
return;
}
}
//todo  ⽂件名相同的复制出现问题
String filePath = NewPath();
//如果⽂件后缀为"java"的进⾏找class复制在指定路径下
dsWith("java")){
filePath = filePath.substring(0, filePath.length()-4)+"class";                            filePath = filePath.substring(4, filePath.length());
arrayList.add(filePath);
sourcePath = classPath + filePath;
File sourceFile =new File(sourcePath);
}
//其他js,jsp复制到
dsWith("js")
|| dsWith("jsp")
|| dsWith("SQL")
|| dsWith("sql")
|| dsWith("cpt")
|| dsWith("frm")
){
File sourceFile =new File(projectPath + filePath);
arrayList.add(filePath);
}
System.out.println(entry);
}
}catch(Exception e){
}
// 写进打包的⽂本⽂件中
FileUtil.writeLines(arrayList, txtFile,"UTF-8");
}
}
System.out.println();
System.out.println("打包⽂件输出为:D:\\web-config\\package !");
System.out.println("com.xs.git_package Done!");
}
public static Repository openJGitCookbookRepository()throws IOException {        FileRepositoryBuilder builder =new FileRepositoryBuilder();
return builder
.readEnvironment()// scan environment GIT_* variables
.findGitDir()// scan up the file system tree
.build();
}
}

本文发布于:2023-05-25 15:20:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/122259.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:获取   打包   复制   路径   回答   程序   存在   增加
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图