'Does Java Git API (JGit or others) Support finding renamed files between commits?

Does Java Git API, Example JGit support finding files between two commits that were renamed?

As example with command line git if I use git status I could see a view along the lines of

renamed: old-file-name -> new-file-name

I would like to get the same functionality (finding old name and new name) but from a java API call.



Solution 1:[1]

With JGit you can fetch diffs between arbitrary commits, branches and tags and get old-path and new-path for changed files. For these you can check if the path is different.

When performing a Diff, the class DiffEntry provides oldPath and newPath which you can compare.

See JavaDoc for DiffEntry.getOldPath() and DiffEntry.getNewPath() for the exact semantics.

The jgit-cookbook has a ready-to-run code-snippet DiffRenamedFile.java, the check for renaming is done here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 centic