| by Arround The Web | No comments

How to Get Shortest Possible Output From git log Containing Author and Date

When developers work on Git, they need to provide the username, email address, password, and similar information. When they make changes in any repository, the system will save them with the provided username, which is called the author name. Like other tracking software, Git also saves the whole information about changes committed by the authors. Developers can get the author’s name, date, and other desired info regarding a particular commit by running the “git log” command.

This study will explain how to get the shortest possible output from the “git log” command containing the author’s name and date.

How to Get Shortest Output From ‘git log’ Containing Author and Date?

To get the shortest output from the git log command containing the author and date, check out the below-listed procedure:

  • Redirect to the Git required repository.
  • Execute the “git log –pretty=format:”%h %an %ad” –date=short <commit-range>”.

First, move to the Git root directory by running the “cd” command along with its path:

$ cd "C:\Users\nazma\Git"

Execute the “git log“ command to get the author name and date:

$ git log --pretty=format:"%h %an %ad" --date=short -5

Here:

  • –pretty” option is used to print the specified output data in a given format.
  • format:” allows you to specify desired information of the required commit.
  • %h” is used to get the short commit id.
  • %an” is used to print the author’s name.
  • %ad” provides the committing date by the author.
  • –date=short” option is used just to print the date instead of time in a readable format.
  • -5” is the particular range which means just printing the author name and date of the most recent 5 commits.

It can be observed that the below-provided output shows the SHA-hash of the last five commits, the author’s name, and the date in shortened:

That’s all! We have provided the easiest way of getting the shortest possible output from the “git log” command containing the author’s name and date.

Conclusion

To get the shortest possible output from the “git log” command containing the author and date, first, move to the Git required repository and execute the “git log –pretty=format:”%h %an %ad” –date=short <commit-range>”. This study demonstrated the method of getting the shortest possible output from the “git log” command containing the author’s name and date.

Share Button

Source: linuxhint.com

Leave a Reply