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
Answer from Ciro Santilli OurBigBook.com on Stack Overflowshell - How to use git show with pretty or format that come up with just commit message brief? - Stack Overflow
command line - How to change Git log date formats - Stack Overflow
Is there a way to format commit messages in Git Bash?
Git log source in pretty format - Stack Overflow
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:

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<<%nwould 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
In addition to --date=(relative|local|default|iso|iso-strict|rfc|short|raw), as others have mentioned, you can also use a custom log date format with
--date=format:'%Y-%m-%d %H:%M:%S' # committer's timezone
--date=format-local:'%Y-%m-%d %H:%M:%S' # current user's timezone
This outputs something like 2016-01-13 11:32:13.
NOTE: If you take a look at the commit linked to below, I believe you'll need at least Git v2.6.0-rc0 for this to work.
In a full command it would be something like:
git config --global alias.lg "log --graph --decorate -30 --all --topo-order --date=format-local:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"
I haven't been able to find this in documentation anywhere (if someone knows where to find it, please comment) so I originally found the placeholders by trial and error.
In my search for documentation on this I found a commit to Git itself that indicates the format is fed directly to strftime. Looking up strftime (here or here) the placeholders I found match the placeholders listed.
The placeholders include:
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time representation appropriate for locale
%d Day of month as decimal number (01 – 31)
%H Hour in 24-hour format (00 – 23)
%I Hour in 12-hour format (01 – 12)
%j Day of year as decimal number (001 – 366)
%m Month as decimal number (01 – 12)
%M Minute as decimal number (00 – 59)
%p Current locale's A.M./P.M. indicator for 12-hour clock
%S Second as decimal number (00 – 59)
%U Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w Weekday as decimal number (0 – 6; Sunday is 0)
%W Week of year as decimal number, with Monday as first day of week (00 – 53)
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number (00 – 99)
%Y Year with century, as decimal number
%z, %Z Either the time-zone name or time zone abbreviation, depending on registry settings
%% Percent sign The others are (from git help log):
--date=(relative|local|default|iso|rfc|short|raw)
Only takes effect for dates shown in human-readable format,
such as when using "--pretty". log.date config variable
sets a default value for log command’s --date option.
--date=relative shows dates relative to the current time, e.g. "2 hours ago".
--date=local shows timestamps in user’s local timezone.
--date=iso (or --date=iso8601) shows timestamps in ISO 8601 format.
--date=rfc (or --date=rfc2822) shows timestamps in RFC 2822 format,
often found in E-mail messages.
--date=short shows only date but not time, in YYYY-MM-DD format.
--date=raw shows the date in the internal raw git format %s %z format.
--date=default shows timestamps in the original timezone
(either committer’s or author’s).
There is no built-in way that I know of to create a custom format, but you can do some shell magic.
timestamp=`git log -n1 --format="%at"`
my_date=`perl -e "print scalar localtime ($timestamp)"`
git log -n1 --pretty=format:"Blah-blah $my_date"
The first step here gets you a millisecond timestamp. You can change the second line to format that timestamp however you want. This example gives you something similar to --date=local, with a padded day.
And if you want permanent effect without typing this every time, try
git config log.date iso
Or, for effect on all your git usage with this account
git config --global log.date iso
Hello. I'm new to using Git in the CLI (Windows), but I've used GitHub Desktop for a brief period before.
In GitHub Desktop, you can format text with backticks (`file_name.txt`) to make it appear as inline code. Is there a way to do something similar in Git Bash? Also, is there some cheat sheet with all possible formats? I've been Googling and the most I've found is "how to write good commits" type articles.
You should take a look at this post. It gives a very nice exemple of a customize git log. And also an oneliner to define it with a Git alias.
To try it, you can type:
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
To define it in an alias:
git config --global alias.lg "git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
To use it :
git lg
To check your configuration:
git config alias.lg
To remove it:
git config --unset alias.lg
date=short
If you want to go further in the configuration, you should look at the Git pretty-formats documentation (placeholders section).
For the date you were talking about, you could change the %cr by %ad because this format respects the --date=option. So you could use --date=short as you want.
Tig
To finish there is a very powerful tool you could use if you are a command line lover like me: Tig
This will become possible with the --pretty=format:%S token supported in the upcoming Git 2.21.0.
Create a minimal example and reverse engineer the format
Create a simple repository, and before any packfiles are created (git gc, git config gc.auto, git-prune-packed ...), unpack a commit object with one of the methods from: How to DEFLATE with a command line tool to extract a git object?
export GIT_AUTHOR_DATE="1970-01-01T00:00:00+0000"
export GIT_AUTHOR_EMAIL="author@example.com"
export GIT_AUTHOR_NAME="Author Name" \
export GIT_COMMITTER_DATE="2000-01-01T00:00:00+0000" \
export GIT_COMMITTER_EMAIL="committer@example.com" \
export GIT_COMMITTER_NAME="Committer Name" \
git init
# First commit.
echo
touch a
git add a
git commit -m 'First message'
# (for python2, remove the two `.buffer`s in the next line)
python -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" \
<.git/objects/45/3a2378ba0eb310df8741aa26d1c861ac4c512f | hd
# Second commit.
echo
touch b
git add b
git commit -m 'Second message'
# (for python2, remove the two `.buffer`s in the next line)
python -c "import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))" \
<.git/objects/74/8e6f7e22cac87acec8c26ee690b4ff0388cbf5 | hd
The output is:
Initialized empty Git repository in /home/ciro/test/git/.git/
[master (root-commit) 453a237] First message
Author: Author Name <author@example.com>
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a
00000000 63 6f 6d 6d 69 74 20 31 37 34 00 74 72 65 65 20 |commit 174.tree |
00000010 34 39 36 64 36 34 32 38 62 39 63 66 39 32 39 38 |496d6428b9cf9298|
00000020 31 64 63 39 34 39 35 32 31 31 65 36 65 31 31 32 |1dc9495211e6e112|
00000030 30 66 62 36 66 32 62 61 0a 61 75 74 68 6f 72 20 |0fb6f2ba.author |
00000040 41 75 74 68 6f 72 20 4e 61 6d 65 20 3c 61 75 74 |Author Name <aut|
00000050 68 6f 72 40 65 78 61 6d 70 6c 65 2e 63 6f 6d 3e |hor@example.com>|
00000060 20 30 20 2b 30 30 30 30 0a 63 6f 6d 6d 69 74 74 | 0 +0000.committ|
00000070 65 72 20 43 6f 6d 6d 69 74 74 65 72 20 4e 61 6d |er Committer Nam|
00000080 65 20 3c 63 6f 6d 6d 69 74 74 65 72 40 65 78 61 |e <committer@exa|
00000090 6d 70 6c 65 2e 63 6f 6d 3e 20 39 34 36 36 38 34 |mple.com> 946684|
000000a0 38 30 30 20 2b 30 30 30 30 0a 0a 46 69 72 73 74 |800 +0000..First|
000000b0 20 6d 65 73 73 61 67 65 0a | message.|
000000ba
[master 748e6f7] Second message
Author: Author Name <author@example.com>
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b
00000000 63 6f 6d 6d 69 74 20 32 32 33 00 74 72 65 65 20 |commit 223.tree |
00000010 32 39 36 65 35 36 30 32 33 63 64 63 30 33 34 64 |296e56023cdc034d|
00000020 32 37 33 35 66 65 65 38 63 30 64 38 35 61 36 35 |2735fee8c0d85a65|
00000030 39 64 31 62 30 37 66 34 0a 70 61 72 65 6e 74 20 |9d1b07f4.parent |
00000040 34 35 33 61 32 33 37 38 62 61 30 65 62 33 31 30 |453a2378ba0eb310|
00000050 64 66 38 37 34 31 61 61 32 36 64 31 63 38 36 31 |df8741aa26d1c861|
00000060 61 63 34 63 35 31 32 66 0a 61 75 74 68 6f 72 20 |ac4c512f.author |
00000070 41 75 74 68 6f 72 20 4e 61 6d 65 20 3c 61 75 74 |Author Name <aut|
00000080 68 6f 72 40 65 78 61 6d 70 6c 65 2e 63 6f 6d 3e |hor@example.com>|
00000090 20 30 20 2b 30 30 30 30 0a 63 6f 6d 6d 69 74 74 | 0 +0000.committ|
000000a0 65 72 20 43 6f 6d 6d 69 74 74 65 72 20 4e 61 6d |er Committer Nam|
000000b0 65 20 3c 63 6f 6d 6d 69 74 74 65 72 40 65 78 61 |e <committer@exa|
000000c0 6d 70 6c 65 2e 63 6f 6d 3e 20 39 34 36 36 38 34 |mple.com> 946684|
000000d0 38 30 30 20 2b 30 30 30 30 0a 0a 53 65 63 6f 6e |800 +0000..Secon|
000000e0 64 20 6d 65 73 73 61 67 65 0a |d message.|
000000eb
Then we deduce that the format is as follows:
Top level:
commit {size}\0{content}where
{size}is the number of bytes in{content}.This follows the same pattern for all object types.
{content}:tree {tree_sha} {parents} author {author_name} <{author_email}> {author_date_seconds} {author_date_timezone} committer {committer_name} <{committer_email}> {committer_date_seconds} {committer_date_timezone} {commit message}where:
{tree_sha}: SHA of the tree object this commit points to.This represents the top-level Git repo directory.
That SHA comes from the format of the tree object: What is the internal format of a Git tree object?
{parents}: optional list of parent commit objects of form:parent {parent1_sha} parent {parent2_sha} ...The list can be empty if there are no parents, e.g. for the first commit in a repo.
Two parents happen in regular merge commits.
More than two parents are possible with
git merge -Xoctopus, but this is not a common workflow. Here is an example: https://github.com/cirosantilli/test-octopus-100k{author_name}: e.g.:Ciro Santilli. Cannot contain<,\n{author_email}: e.g.:cirosantilli@mail.com. Cannot contain>,\n{author_date_seconds}: seconds since 1970, e.g.946684800is the first second of year 2000{author_date_timezone}: e.g.:+0000is UTCcommitter fields: analogous to author fields
{commit message}: arbitrary.
I've made a minimal Python script that generates a git repo with a few commits at: https://github.com/cirosantilli/test-git-web-interface/blob/864d809c36b8f3b232d5b0668917060e8bcba3e8/other-test-repos/util.py#L83
I've used that for fun things like:
- Who is the user with the longest streak on GitHub?
- https://www.quora.com/Which-GitHub-repo-has-the-most-commits/answer/Ciro-Santilli
- https://github.com/isaacs/github/issues/1344
Here is an analogous analysis of the tag object format: What is the format of a git tag object and how to calculate its SHA?
Before you head down this path much further, I might recommend that you read through the section in the Git Manual about its internals. I find that knowing the contents of this chapter is usually the difference between liking Git and hating it. Understanding why Git is doing things the way it does often makes all of the sort of weird commands it has for things make more sense.
To answer your question, the gibberish that you are seeing is the data for the object after it has been compressed using zlib. If you look under the heading "Object Storage" in the link above you can see some details about how this works. This is the short version of how files are stored in Git:
- Create a Git specific header for the content.
- Generate a hash of the concatenation of the header + content.
- Compress the concatenation of the header + content.
- Store the compressed data to disk in a folder with a name equal to the first two characters of the data's hash and a file name with the remaining 38 characters.
So that answers your second question, a folder will contain all of the compressed objects that begin with the same two characters, regardless of their contents.
If you want to see the contents of a blob, all you have to do is decompress it. If you just want to view the contents of the file, this can be done easily enough in most programming languages. I would warn you against trying to modify data, however. Modifying even a single byte in a file will change its hash. All of the metadata in Git (namely, directory structures and commits) are stored using references to hashes, so modifying a single file means that you must also update all objects downstream from that file that reference that file's hash.
Then you have to update all the objects that reference those hashes. And on, and on, and on... Trying to achieve this becomes very, very complicated very quickly. You'll save yourself a lot of time and heartache by just learning Git's built in commands.