Personalize the output format of your git log

Source: Internet
Author: User
Tags iso 8601 iso 8601 format hex code

Git has become one of many programmers ' everyday tools.

Git log is a great tool for looking at git history, but the default format is not particularly intuitive.

Many times you want to make it easier to output more or less information, here is a list of the format of several git logs.

Can be customized according to their own needs.

The git log command can accept a--pretty option to determine the format of the output.

If we just want to output hash.

Git uses a variety of placeholder to decide what to display:
The following is from here

  • %h:commit Hash
  • %H: Shortened commit hash
  • %t:tree Hash
  • %t: Shortened tree hash
  • %p:parent Hashes
  • %p: Shortened parent hashes
  • %an: Author's name
  • %an:mailmap's author name (. Mailmap correspondence, details refer to Git-shortlog (1) or git-blame (1))
  • %ae: Author Email
  • %ae: Author mailbox (. Mailmap correspondence, details refer to Git-shortlog (1) or git-blame (1))
  • %ad: Date (format established by--date=)
  • %ad: date, RFC2822 format
  • %ar: Date, relative format (1 day ago)
  • %at: date, UNIX timestamp
  • %ai: Date, ISO 8601 format
  • %CN: Submitter Name
  • %CN: Submitter name (. Mailmap correspondence, details refer to Git-shortlog (1) or git-blame (1))
  • %CE: Submitted by email
  • %ce: Submitter Email (. Mailmap correspondence, details refer to Git-shortlog (1) or git-blame (1))
  • %CD: Date of submission (format established by--date=)
  • %CD: submission date, RFC2822 format
  • %CR: submission date, relative format (1 day ago)
  • %CT: Date of submission, UNIX timestamp
  • %ci: Date of submission, ISO 8601 format
  • %d:ref Name
  • %e:encoding
  • %s:commit Information Title
  • %f:sanitized subject line, suitable for a filename
  • %b:commit Information Content
  • %n:commit notes
  • %gd:reflog selector, e.g., Refs/[email protected]{1}
  • %gd:shortened Reflog selector, e.g., [email Protected]{1}
  • %gs:reflog subject
  • %cred: Switch to Red
  • %cgreen: Switch to Green
  • %cblue: Switch to Blue
  • %creset: Reset Color
  • %c (...): Make color, as described in color.branch.* config option
  • %m:left, right or boundary mark
  • %n: Line break
  • Percent: a raw%
  • %x00:print a byte from a hex code
  • %w ([[, [,]]): Switch line wrapping, like the-w option of Git-shortlog (1).

In addition, the--graph option displays the ASCII legend of the branch.

If you have customized a preferred output scheme, you can save it to git config, or set alias for later use.

~/.gitconfig Add:

[Alias]    

or run:

git config--global alias.lg "log--graph"

Finally, a few others to share the example, a little bit slow, but you can look at the git log custom effect, the effect is cool.

git log--graph--pretty=format: '%cred%h%creset-%c (yellow)%d%creset%s%cgreen (%CR)%creset '--abbrev-commit--date= Relative

Personalize the output format of your git log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.