Git log
offers useful options for filtering. This card provides a short overview.
By message
Only commits that include a specific string in their commit message
git log --grep="tracker id"
By file
Only commits that introduced changes to a specific file
git log -- foo.rb bar.rb
Note
In case the file was renamed or moved the
--follow
option can be helpful
git log --follow -- foo.rb
By content
If you want to know when a specific line of code was added in the project
git log -S"def function_name"
By range
If you want to know which commits have been added between two commits.
git log base_branch..compare_branch
will show you how many commits were added to compare_branch
since base_branch
.
By count
git log -n
to show only the last n
commits.
By date
- You can also use
git log --since 2023-02-17
to show only commits from that date until today. - If you want all the dates until a specific date, you can use
git log --until 2021-01-19
Note
The
--since
and--until
flags are synonymous with--after
and--before
, respectively.
- You can combine both too:
git log --after="2014-7-1" --before="2014-7-4"
You can use references like "2 years 1 day 3 minutes ago" and "yesterday": git log --after="yesterday"