If you are using Git for a while you should have come across git log. As everyone knows, the git log is a simple command that helps us to view the changes or project history. Even with that simplicity, it is a very powerful tool and it comes with numerous options that help us to view the project changes and its structure. We will see some of the most used options in this article. git log —oneline git --oneline log This command helps you to view the commits in a cleaner way. It condenses each commit to a line and has only minimal information like shorter commit hash, commit message. Filter commits by time period These commands will filter out the commits by the given time period. For example, will only filter commits after the given time period and will only filter commits before the given time period. — after — before git --after= log "2020-15-05" The above command will show only commits after May 15th, 2020 git --after= --before= log "2020-15-05" "2020-25-05" The above command will show only commits from May 15 to May 25 You can also use the following date formats git --after= // shows only commits from yeserday git --after= // shows only today commits git --before= // omits last 10 days commits git --after= //show only commits from last week git --after= git --after= // shows only last 2 months commits log "yesterday" log "today" log "10 day ago" log "1 week ago" log "2 week ago" log "2 month ago" git log with diff changes git -p log This command will show the log with the diff changes. So that you can know the changes done in each commit. In the above image, you can see the git diff changes. Filter commits by author git --author= log "Srebalaji" The above command will filter out the commits done by the particular author. Note that the Git filters out by regex pattern. So don’t worry about the exact name match or case sensitivity. Git log can take multiple options so you can combine options for your need. For example, git --after= --author= -p log "1 week ago" "srebalji" The above command will filter commits for the past week by the respective author and also shows the diff changes. Filter commits by log messages Sometimes, you need to filter commits by log messages. Git accepts a regex pattern to search for the log messages and displays all the matched commits. git --grep= log "ISSUE-43560" The above command will filter commits by the respective pattern. And remember by default it’s case sensitive. To make the search , you can pass parameter case insensitive -i git -i --grep= log "issue-43560" The below command is using a regex pattern search and will search for both the issue ids. git -i --grep= log "issue-43560\|issue-89786" Filter commits by files Sometimes you need all commits changes that have affected some particular files. This will come in hand in many places. git main.rb log This command will filter commits that made changes to the respective file. You can also pass multiple files to it. git main.rb search.rb login.rb log You can see I have passed three files to filter out. Remember you can also pass multiple options. git -i --grep= main.rb search.rb log "fix " This command will filter out commits changes done to the specified files and also will match the log message by the given search pattern. Filter commits by file content You may need to search for a specific string in the source code that has been added in the commit history. This can be possible by git -S log "function login()" The above command will search for the string “function login()“. By default, it’s case sensitive. You can make it case-insensitive by adding And to view the content you can view the diff changes. -i. git -i -S -p log "function login()" Show only merge commits This command helps us in knowing the merges done to the current branch. git --merges log The above command will show only the merge commits in the current branch. Nothing more. Showing diff between branches We have already seen this command in one of our previous issues. git master..develop log This command will help you show all the commits from develop but that are not present in the master branch. In this way, you can know that how many new commits are added to the develop branch that is not present in the master branch. And make sure you have the updated changes in the local before comparing. Custom formatting log messages Git also provides options to custom format our log messages. You can check out for more options. custom pretty options For example, git --pretty=format: log "%Cred%an - %ar%n %Cblue %h -%Cgreen %s %n" You can see in the above image that the commit logs are custom formatted. It’s pretty easy and it comes in handy if you want to view only specific details of the log. That's it. Hope you learned something new :) Thank you for reading :) :) This post was originally posted in the newsletter GitBetter . If you are interested in leveling up your game in Git, you can subscribe to it. Previously published at https://gitbetter.substack.com/p/useful-tricks-you-might-not-know