Git commit history- Customize the output with colors 🌈
Tags: git, commandline, commit, tools
Published: 2020-06-24 20:28:26

When you are working with Git, git-log is a powerful command for showing the commit history.
git-log supports a lot of options/parameters in order to control the output and you (as developer) can decide what you want to see.
I know, what you want to see, it depends on your needs, but let me show you my git log options that I usually use in order to display one commit per line and with some color. Colors are useful not just for aestetics but to highlight some useful informations.
If you are using "git log" with no options you will see something like that:
```
commit a5e4001cd88b3dd3ff374856514e20cfffe4379c (HEAD -> master, origin/master)
Author: Roberto B <your-email-address@domain.com>
Date:   Fri Jun 19 07:48:04 2020 +0200

    Clean up runtime parameters in order to improve readability
```
For each commit you will see more than one line with:
- the **hash** of the commit (the commit identifier), 40 characters long;
- the **ref name** (if the commit is related with branch or tag or HEAD);
- The **author** with full name and email address;
- the **date** of the commit in a long format;
- the commit **message**.

## 1 commit - 1 line
If you want to see one commit per line you need to use **--pretty=oneline** option:
```sh
git log --pretty=oneline
```
In this case you will see:
- the hash of the commit, 40 characters long;
- the **ref name** (if the commit is related with branch or tah or HEAD);
- the commit **message**.

If 40 characters for hash is too long, you can use the shorter values for hash (but also unique) with **--abbrev-commit** option:
```sh
git log --pretty=oneline --abbrev-commit
```
Is it better? 

## Let's customize the format
If you want to customize the output you can use **format** option combined with **--pretty**.
With **--pretty=format** you can use some placeholders in order to specify which information you want to show.
For example:
```sh
git log --pretty=format:'%h %s'
```
You want to see:
- %h: abbreviated commit hash (7 characters, like --abbrev-commit option);
- %s: the subject of the comment of the commit.

## More colors
With placeholders you can use also colors (%C<colorname>):

For example like the example above, if you want to see the hash commit (%h) with red color:
```sh
git log --pretty=format:'%Cred%h%Creset %s'
```
With **%Cred** you want to use the red color. With **%Creset** you want to reset the default color.

## More colors, more informations

Usually I use this **git log** configuration:
```sh
git log --pretty=format:'%Cred%h%Creset %C(bold blue)%an%Creset %Cgreen%cr%Creset %s%C(bold red)%d%Creset'
```
where:
- **%Cred%h%Creset**: the hash commit (%h) in red color;
- **%C(bold blue)%an%Creset**: the author name (%an) with bold blue color %C(bold blue);
- **%Cgreen%cr%Creset**: the committer date relative %cr (for example relative means: "5 minutes ago") in green color %Cgreen
- **%s**: the commit message (the subject with %s placeholder);
- **%C(bold red)%d%Creset**: the ref names %d in red bold color.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/r3rulx4kovc7dn3dve3s.png)

Ok, now that you understood the basics, you can go to the official documentation https://git-scm.com/docs/pretty-formats and start to play with all the placeholders and customize your git log history.