Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

How to use Git Log command efficiently

If you’re a modern developer and using Git as your choice of the version control system, you would have used the git log command at some point of time in your career.

Essentially, the git log command shows the list of commit logs. So, if we run it in one of the Git repositories in its bare minimum form, here’s what this would look like.

As you can tell, the git log command would show the list of all the commits with their commit hash, author, time of the commit, and the message. It would also show on which head the current commit at.

Now, this much amount of information might sound like a good deal but what if I tell you there are some options that when used with this command can show a lot more information. And this is what I’m going to discuss about some of my favorite options in this article.

The -p option

The vanilla git log doesn’t show what has been changed in a particular commit. To work around this, use the git log command with the -p option like so.

$ git log -p

This will show everything that the git log command shows and in addition to that, it will also show the diff output for all the files changed for a particular commit like so.

Pretty nice improvement to git log already, no?

The --compact-summary option

When running git log with the --compact-summary option, it will show the condensed summary of file changes for commits without all the diff fluff.

$ git log --compact-summary

This is what the output looks like.

As you can tell, it shows the number of files changed along with the number of insertion (+) and deletion (-) done for a particular commit.

The --name-only option

This option is just like --compact-summary but a lot more compact where it will only show the list of files that have been modified for a particular commit, omitting all the other details.

$ git log --name-only

This is what the output looks like.

The --shortstat option

This option would only show the count of the total number of files changed along with the count of insertion and deletion for a particular commit.

$ git log --shortstat

This is what the output looks like.

The --oneline option

Last but not least. A lot of times you don’t need all the details like author, diff, and date of the commit. Maybe you only need the commit hash and the message.

In such scenarios, you can use the --online option that would show the absolutely bare minimum. i.e. commit hash and the message.

$ git log --oneline

This is what the output looks like.

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?