Colors and authors in git log on Windows?
Asked Answered
O

3

5

Using Windows 10 Pro 64-bit I found a nice command to list the Git history, showing HEAD, branches, and tags as stand-out colors. Nice!

git log --oneline --decorate --graph --all

But I don't see any dates or authors! So I find another nice command:

git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short

Also very nice---now I can see dates and authors. But all the pretty colors are gone (except for the graph). HEAD, branches, and tags are all the same color as the rest of the log, making it hard to pick them out.

How do I get the colors back for the commit pointers while keeping the date and authors?

Outlook answered 1/3, 2016 at 18:16 Comment(0)
I
5

You can wrap your format string with %C(auto) and %C(reset) to color the output automatically, like so:

%C(auto)<insert your formatting here>%C(reset)

So, using the format you provided:

git log --pretty=format:"%C(auto)%h %ad | %s%d [%an]%C(reset)" --graph --date=short

It will use git's default color for things like branches (remote in red, local in green, HEAD in cyan etc) and commit refs.

Incoercible answered 2/11, 2021 at 17:48 Comment(1)
Very nice! It addressed the issue precisely. I'll add a bounty as a reward for this answer, because it's not every day that someone answers a question so directly and so simply. Thanks.Outlook
N
4

This should do what you're looking for:

git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

enter image description here

Taken from this post

Nitz answered 1/3, 2016 at 19:7 Comment(2)
But I don't have the date. I can figure out how to add them in, but all the branch pointers are the same color, unlike git log --oneline --decorate --graph --all.Outlook
I've changed the entry to add the date, the branch color should be fixed.Nitz
S
3

Add the git log --decorate --graph and it will display branches, tags etc.

--decorate [=short|full|no]

Print out the ref names of any commits that are shown. If short is specified, the ref name prefixes refs/heads/, refs/tags/ and refs/remotes/ will not be printed. If full is specified, the full ref name (including prefix) will be printed. The default option is short

--graph

Draw a text-based graphical representation of the commit history on the left hand side of the output. This may cause extra lines to be printed in between commits, in order for the graph history to be drawn properly


For windows

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.<<

You can use the log format flag

# print out the git log
git log 

# print out the branches split and merge points
--graph 

# use the --pretty=format:... to choose which data to extract from the log
# (commit) entry and print it out.

# Set colors with the %C<color> & %Creset for resetting back to the default color

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


On unix

  • If you use uxin based OS you can use this .githelpers

Output of the .githelprs script:

enter image description here

Spectrometer answered 1/3, 2016 at 20:6 Comment(1)
this is a very complete answer. as per docs, thank you. I would also like to add that some libraries can help with it too eg: github.com/CookPete/auto-changelogSeoul

© 2022 - 2024 — McMap. All rights reserved.