0

I am struggling to get the changed File list for Each commit using Jgit from Github repository. please find my sample code and output for your references. We are expecting for each commit we want to know what are files are modified or added or deleted.

        File gitWorkDir = new File("D:/Eka_App/Log_Audit");
        Git git = Git.open(gitWorkDir);
        Repository repo = git.getRepository();
        String path = "Database";

        Iterator<RevCommit> revCommits = git.log().addPath(path).call()
                .iterator();

        while (revCommits.hasNext()) {
            RevCommit commit = revCommits.next();
            System.out.println("commit descr: " + commit.getShortMessage()
                    + ", Commit id : " + commit.getId() + ",Commit time: "
                    + commit.getCommitTime() + ", Auther: "
                    + commit.getAuthorIdent());

            RevTree tree = commit.getTree();

            TreeWalk treeWalk = new TreeWalk(repo);
            treeWalk.addTree(tree); // option 1

            treeWalk.setRecursive(false);

            treeWalk.setPostOrderTraversal(false);
            while (treeWalk.next()) {
                if (treeWalk.getPathString().contains("Database")) {
                    if (treeWalk.isSubtree()) {
                        // System.out.println("dir: " +
                        // treeWalk.getPathString());
                        treeWalk.enterSubtree();
                    } else {
                        System.out.println("file: " + treeWalk.getPathString());
                    }
                }
            }
        }
  • Out put coming like this now : – kesavulu Dec 20 '19 at 05:55
  • Your code tries to list all the files contained in a commit. Your question sounds like you want to get the changes in relation to the parent commit. This has been answered here already: https://stackoverflow.com/questions/28785364/list-of-files-changed-between-commits-with-jgit – Rüdiger Herrmann Dec 20 '19 at 09:37

0 Answers0