The purpose of any version control system is to record changes to your code. This gives you the power to go back into your project history and see who contributed what and when and figure out where bugs were introduced. But, having all of this history available is useless if you don’t know how to navigate it. That’s where the git log command comes in. Below various git log options that will be very helpful while maintaining a big project:
--oneline option will give you a output of commits to a single line. By default it will show you the commit ID and first line of the commit message.
aniruddha ~/Desktop/foobar master $ git log --oneline 505a2c6 (HEAD -> master) Add the file hellomars.txt and update helloworld.txt fb8c32d First commit
The most basic filter that git gives us the limit the number of commits. You can pass
-<n> after the
$ git log -3
When you are looking for commits created by a specific person then
--author="name" will be the option you have to use. This will return all commits matches with the author name you have given.
$ git log --author="Aniruddha"
You can use regular expressions to search for commits. In the below example the following commands searches for commits by either Aniruddha or Sayan.
$ git log --author="Aniruddha\|Sayan"
By commit message
To filter the commits by their commit message, use the
--grep flag. This works like the
--author flag discussed in the above but it matches against the commit message instead of the author.
$ git log --grep="First"
Some times you are only interested in changes that happened to a particular file. To see the history related to a file you just have to to pass the file path. Below we want to see the commits related to
$ git log -- foo.py
See changed file names
If you want to see the files you have changed according to your git commit then execute the below git command.
$ git log --name-only
Thank you 🙂