RevCommit
has a getCommitTime()
method but it returns an int
and it does not have an author time. How can I get the author and commit date from a RevCommit
?
You can use the git show command with the --pretty=fuller flag to check if the commit author date and commit date are different. If the author and commit date are different, you can manually change the commit date in the URL to see the commit details.
To get the commit date, we can use the log command, with the same arguments as before, but with the addition of -1: The only difference is the -1 parameter, which tells this command to return date information for only 1 commit. Using -2 here would return 2 commits, and so-on.
To change the author information that is used for all future commits in the current repository, you can update the git config settings so that they only apply here: To update the author information your computer uses on a global level (e.g. for all repositories), add the --global flag:
How do you view the revision history in Git? Let’s say you want to view all commits to the Git repository. The git log command returns all of the commits that have been made to the repository. This command lists the latest commits in chronological order, with the latest commit first. The syntax of the git log command is given below −
Like so:
RevCommit commit = ...;
PersonIdent authorIdent = commit.getAuthorIdent();
Date authorDate = authorIdent.getWhen();
TimeZone authorTimeZone = authorIdent.getTimeZone();
PersonIdent committerIdent = commit.getCommitterIdent();
...
Also see API documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With