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
Enter, and then we need to hit
q to exit reading the log.
This post is to demo the –online parameter that can be added to the git log statement. Adding this parameter will return a condensed log, which shows the first part of the commit hash and message on one line.
In my following example, I’m running a simple git log command on one of my Repos.
Now, I’m going to run the same command, adding in the –oneline parameter.
This is a bit too much logs on screen. We can also 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.
# show most recent 2 commits git log -2 # show most recent 5 commits on one line git log -5 --oneline
As well as this, 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'
That’s it for this tip, checkout my other Git posts here if you would like more tips on this Category!