Menu & Search

Git Log Show in One Line (–oneline)

Git Log Show in One Line (–oneline)

To check our commit history on a Repository within Git, we use the git log command. When using this command we scroll through the commit log within our Terminal by hitting the Enter key, and then we need to hit q on our keyboard to exit reading the git log.

This post is to demo the --online parameter that can be added to the git log statement. Adding this parameter to the git log command will return a condensed commit log history, which shows the first part of the commit hash and message on one line.

The following is included in this demo post:
# Git Log
# Git Log –OneLine
# Git Log –OneLine -5
# Git Log –OneLine with Custom Formatting

Git Log

In the following example, I’m running the standard git log command on one of my Repos. This is what we’d use if we want information including full commit hashes, commit dates/times, and authors.

Git Log

Git Log –Oneline

This next example shows will return a condensed commit log history. It’s the same command as above but we’re adding the --oneline parameter.

# Show git log in one line
git log --oneline
Git Log --oneline

Git Log –Oneline -5

You might think the above shows too many logs on the screen. We can pass in a line number parameter for it to return a specific number of commits.

This next example shows with and without the above –oneline parameter. We limit the number of commits/rows being returned by adding ‘-5‘ (can be any number).

# show most recent 2 commits
git log -2

# show most recent 5 commits on one line
git log -5 --oneline
Git Log -5

Git Log –Oneline -5 with Custom Formatting

We can amend the formatting of the returned list, including changing colours, adding in commit times, and adding the contributor.

This would be ideal if it was added as a function on your Terminal Profile.

# show most recent 5 commites on one line, with formatting
git log -5 --graph --pretty=format:'%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr) %C(yellow)<%an>%Creset'
Git Log Formatting

That’s it for this tip, check out my other posts on this topic in the Git Tag if of interest.

0 Comments