How to find newly added,deleted and modified files in git repository using Git Api in Java [closed]

StackOverflow https://stackoverflow.com/questions/18556639

  •  27-06-2022
  •  | 
  •  

Question

Using Git Api in Java(Egit and Jgit Api),I want to trace out newly added,deleted and modified files in Git repository.How can I do this??

Was it helpful?

Solution

You can have a look at JGit unit tests for finding a lot of examples.

That includes org.eclipse.jgit.api.StatusCommandTest

Git git = new Git(db);
writeTrashFile("a", "content of a");
writeTrashFile("b", "content of b");
writeTrashFile("c", "content of c");

git.add().addFilepattern("a").addFilepattern("b").call();

Status stat = git.status().call();   // git status right there

assertEquals(set("a", "b"), stat.getAdded());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top