Is it possible to resolve the date and time when a certain file was committed for the first time using JGit?
Git equivalent would be listing the first commit, like:
git log --format=%aD <FILE> | tail -1
Is it possible to resolve the date and time when a certain file was committed for the first time using JGit?
Git equivalent would be listing the first commit, like:
git log --format=%aD <FILE> | tail -1
A
RevWalk
can be used as follows to obtain the first commit that contains 'file.txt'In the example the history starts at
HEAD
. Adjust themarkStart()
call the start from somewhere else or callmarkStart()
multiple times to include several start points.The
PathFilter
excludes commits that do not contain the given repository-relative path name. And finally the twosort()
calls take care that commits are ordered by their time stamp (newest first) in reverse order. Hence the oldest commit that contains the given file is returned bynext()
.Be aware that the commit passed to
markStart()
must be from the same revision walker, i.e. it must be obtained with a call toparseCommit()
from the same revWalk instance. See also this thread for more details.