A GIT file location may change through GIT PULL or change of the branches. How can I track the file position change? I am using jGIT, an Eclipse library for GIT. Currently I do:
final PullCommand pullCommand = git.pull().setRemote("origin").setRemoteBranchName(git.getRepository().getBranch());
It is worth to keep in mind, that Git (and thus JGit) tracks content, not files. When a file is moved or renamed, Git just sees that a file was added with the new name, and a file was deleted with the old name.
With
DiffFormatter::scana list of files that have been changed between two states of a repository (e.g. two commits, or a commit and the work dir) can be obtained. The method returns a list ofDiffEntrys, each describing an added, deleted, or modified file.The
DiffFormattermay be configured with aFollowFilterorsetDetectRenames(true)to use heuristics to detect renames. See the resultingDiffEntry'schangeTypeor compareoldPathandnewPath.If you intend to track changes to the working directory, you may consider using a file watcher instead. This would also include changes made outside of your application.