Skip to content

Instantly share code, notes, and snippets.

@palashmon
Created February 19, 2024 10:11
Show Gist options
  • Save palashmon/79387fae84636eb10a85c9d9d266d200 to your computer and use it in GitHub Desktop.
Save palashmon/79387fae84636eb10a85c9d9d266d200 to your computer and use it in GitHub Desktop.
Enhanced Git Log Formatting

Enhanced Git Log Formatting

Overview

The git log command is a powerful tool for viewing the commit history of a Git repository. By default, it displays a detailed list of commits, including commit hashes, commit messages, author names, dates, and branch information. However, customizing the output format can make the log more informative and visually appealing.

In this gist, we'll explore two enhanced git log commands that use custom formatting to provide a clearer and more concise view of the commit history.


Git Command 1

git log --pretty=format:"%C(red)%h%Creset %<(60,trunc)%s (%C(green)%ar%Creset) [%C(cyan)%an%Creset]" --date=short --decorate --all -n 20

Description:

  • This command displays a compact and informative log of the last 20 commits.
  • It formats each commit entry with the commit hash displayed in red, followed by the commit message truncated to 60 characters and aligned to the left. The commit message is enclosed in parentheses and is followed by the relative commit date displayed in green. Finally, the author's name is displayed in cyan within square brackets.
  • The --date=short option formats the commit dates in a shorter form.
  • The --decorate option adds branch and tag names to commits.
  • The -n 20 option limits the output to the last 20 commits.

Git Command 2

git log --pretty=format:"%C(red)%h%Creset %<(50,trunc)%s %C(green)%d%Creset [%C(cyan)%an%Creset]" --date=short --decorate --all -n 20

Description:

  • This command also displays a concise log of the last 20 commits.
  • It formats each commit entry with the commit hash displayed in red, followed by the commit message truncated to 50 characters and aligned to the left. After the commit message, branch and tag information is displayed in green. Finally, the author's name is displayed in cyan within square brackets.
  • The -n 20 option limits the output to the last 20 commits.

Feel free to share and modify these commands according to your needs. We welcome feedback from users regarding their experience with the provided commands. If you have used these scripts or made modifications based on your needs, we would appreciate hearing from you. Please share your feedback and any customized versions of the commands to help improve the Git logging experience for the community.

Happy Git logging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment