Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pretty format string equivalent of oneline, including colors

Tags:

git

I am trying to recreate the Git format setting of oneline as a format string (in order to extend it further).

So for this command

git log --format=oneline

What is the format string equivalent of oneline? The closest I can get is

git log --format="%h %d %s"

However, this does not produce any colors. I know I can hard code some of them, like the commit hash. But the %d has dynamic colors, depending on what it shows.

like image 335
Klas Mellbourn Avatar asked May 30 '15 22:05

Klas Mellbourn


People also ask

What is pretty format in git?

<full-commit-message> reference. <abbrev-hash> (<title-line>, <short-author-date>) This format is used to refer to another commit in a commit message and is the same as --pretty='format:%C(auto)%h (%s, %ad)' . By default, the date is formatted with --date=short unless another --date option is explicitly specified.

How do I make my git log pretty?

A simple fix is to pass the --pretty=oneline parameter, which makes it all fit on a single line. It's taking up less space, but missing crucial information like the date of the commit. There are longer versions of that same --pretty parameter. In fact, it allows you to specify all the fields you want in the output.

What is-- decorate in git?

This is commonly used in conjunction with the --oneline and --decorate commands to make it easier to see which commit belongs to which branch: git log --graph --oneline --decorate.

How git log works?

The git log command shows a list of all the commits made to a repository. You can see the hash of each Git commit, the message associated with each commit, and more metadata. This command is useful for displaying the history of a repository.


1 Answers

Turn on auto color

git log --format="%C(auto) %h %d %s"

and the output will look like this

enter image description here

From the git log documentation

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

like image 140
René Link Avatar answered Nov 15 '22 14:11

René Link