This is an old revision of the document!
Overview
How to search through commit history using either of:
git loggit grep
Examples use the Git repository for the “Pro Git” book found here.
Searching with "git log"
The git log command supports looking for commits by the content of their commit messages, or even the content of the diff they introduced. All examples here can be enhanced with the regular git log options.
Searching for author
$ git log --author="Robert P. J. Day" $ git log --author="Robert P\. J\. Day" $ git log --author="P\. J\." $ git log --author="Robert P. J. Day" --oneline $ git log --author="Robert P. J. Day" --oneline | wc -l $ git log -i --author="robert p. j. day"
Searching by date range
--since=<date>, --after=<date>
Show commits more recent than a specific date.
--until=<date>, --before=<date>
Show commits older than a specific date.
So:
$ git log --since="Feb 1, 2019" $ git log --author="Ben Straub" --since="Jan 1, 2019" --until="Feb 1, 2019"
Using the "--grep" option
--grep=<pattern>
Limit the commits output to ones with log message that
matches the specified pattern (regular expression). With
more than one --grep=<pattern>, commits whose message
matches any of the given patterns are chosen (but see
--all-match).
...
--all-match
Limit the commits output to ones that match all given
--grep, instead of ones that match at least one.
--invert-grep
Limit the commits output to ones with log message that do
not match the pattern specified with --grep=<pattern>.
Examples:
$ git log --grep="Tagging" --oneline | wc -l 6 $ git log --grep="tagging" --oneline | wc -l 9 $ git log -i --grep="tagging" --oneline | wc -l 13 $
$ git log -i --grep="tagging" --grep="rewording" --oneline | wc -l
66
$ git log -i --grep="tagging" --grep="rewording" --all-match --oneline | wc -l
2
$ git log -i --grep="tagging" --grep="rewording" --all-match
commit 110e27b003c10b4574ee49a47a090e125d6c4811
Merge: 72d6a54 a402fcf
Author: Ben Straub <ben@straub.cc>
Date: Mon Oct 16 10:30:02 2017 -0700
Merge pull request #866 from rpjday/tagging
Add TIP to tagging section explaining "-l"; also some rewording
commit a402fcf53fb0d8d0c165ca9ee9ce233ea955cb85
Author: Robert P. J. Day <rpjday@crashcourse.ca>
Date: Mon Oct 16 01:44:21 2017 -0700
Add TIP to tagging section explaining "-l"; also some rewording
- Clarify the need for [-l|--llist]
- Some minor rewording
$