Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git show with pretty or format that come up with just commit message brief?

Tags:

git

shell

github

The output should look like git log, no any file and code changes just commit message brief, as below:

commit <sha1>
Author: <author>
Commit: <committer>
<title line>
<full commit message>

I have got some tips that git show with pretty or format set to 'full', but I don't know how to use it.

like image 704
Wilence Avatar asked Apr 17 '16 13:04

Wilence


People also ask

What is pretty format in git?

Pretty-print the contents of the commit logs in a given format, where <format> can be one of oneline, short, medium, full, fuller, reference, email, raw, format:<string> and tformat:<string>.

How do I show last changes made with commit message?

Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

Which command shows the one commit per line with just the short SHA and commit message?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message. It will be used as follows: $ git log --oneline.


2 Answers

git show --format="YOUR_FORMAT" -s

-s suppresses the diffs from showing.

YOUR_FORMAT is documented at:

man git-log

section PRETTY FORMATS

For example, to get just commit SHAs and author email for a few SHAs:

git show --format="%H %ae" -s 62f6870e4e0b384c4bd2d514116247e81b241251 96ee0246ce52012644dd18cf360e64c49016fb7f

gives output for format:

62f6870e4e0b384c4bd2d514116247e81b241251 [email protected]
96ee0246ce52012644dd18cf360e64c49016fb7f [email protected]

To add newlines and more fields to the format, you could do:

git show --format=$'%H\n%ae\n%an\n' -s 62f6870e4e0b384c4bd2d514116247e81b241251 96ee0246ce52012644dd18cf360e64c49016fb7f

Which gives output for form:

62f6870e4e0b384c4bd2d514116247e81b241251
[email protected]
Ciro Santilli

96ee0246ce52012644dd18cf360e64c49016fb7f
[email protected]
Ciro Santilli

Im using this script (as alias):

https://github.com/vheon/home/blob/master/.githelpers

git alias:

l = "!bash -c 'source ~/.githelpers && pretty_git_log'"

the output is this:

enter image description here


You will have to use your own git log --pretty=format options.

In the --pretty you can set colors and choose any content you would like to display


format:<string>

The format: format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n.

E.g, format:The author of %h was %an, %ar%nThe title was >>%s<<%n would show something like this:

The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<

The placeholders are:

%C(…): color specification, as described in color.branch.* config option; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.

%C(…): color specification, as described in color.branch.* config option; adding auto, at the beginning will emit color only when colors are enabled for log output (by color.diff, color.ui, or --color, and respecting the auto settings of the former if we are going to a terminal). auto alone (i.e. %C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.

%Cblue: switch color to blue
%Cgreen: switch color to green
%Cred: switch color to red
%Creset: reset color
%D: ref names without the " (", ")" wrapping.
%G?: show "G" for a Good signature, "B" for a Bad signature, "U" for a good, untrusted signature and "N" for no signature
%GG: raw verification message from GPG for a signed commit
%GK: show the key used to sign a signed commit
%GS: show the name of the signer for a signed commit
%H: commit hash
%N: commit notes
%P: parent hashes
%T: tree hash
%aD: author date, RFC2822 style
%aE: author email (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%aI: author date, strict ISO 8601 format
%aN: author name (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%ad: author date (format respects --date= option)
%ae: author email
%ai: author date, ISO 8601-like format
%an: author name
%ar: author date, relative
%at: author date, UNIX timestamp
%b: body
%cD: committer date, RFC2822 style
%cE: committer email (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%cI: committer date, strict ISO 8601 format
%cN: committer name (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%cd: committer date (format respects --date= option)
%ce: committer email
%ci: committer date, ISO 8601-like format
%cn: committer name
%cr: committer date, relative
%ct: committer date, UNIX timestamp
%d: ref names, like the --decorate option of git-log(1)
%e: encoding
%f: sanitized subject line, suitable for a filename
%gD: reflog selector, e.g., refs/stash@{1}
%gE: reflog identity email (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%gN: reflog identity name (respecting .mailmap, see git-shortlog(1) or git-blame(1))
%gd: shortened reflog selector, e.g., stash@{1}
%ge: reflog identity email
%gn: reflog identity name
%gs: reflog subject
%h: abbreviated commit hash
%m: left, right or boundary mark
%n: newline
%p: abbreviated parent hashes
%s: subject
%t: abbreviated tree hash
%w([<w>[,<i1>[,<i2>]]]): switch line wrapping, like the -w option of git-shortlog(1).
%x00: print a byte from a hex code

like image 43
CodeWizard Avatar answered Nov 15 '22 20:11

CodeWizard