Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I query the git commit history?

Tags:

git

So maybe I'm asking the question the wrong way, but I cannot find information on how to do this. I have a large git repository with many commits over the last two years by many people. Is there a way that anyone has ever figured out for how I query the git commit history? I am an SQL guy, so I'm used to using SQL to query a database (or even grep or find to query my filesystem).

These are example queries I'd like to run:

  • All commits whose message contains the text "xyz"
  • All commits whose message is LIKE '%xyz'
  • All commits done by user [email protected]
  • All commits that are the child of commit 1234abcd
  • All commits between date 1 and date 2
  • AND/OR combinations of the above

If I could even export the git log, then I could use a different tool to get most of this information (though ancestral querying/querying by branch might be difficult). Sometimes it would be nice to just go to the command line and query really quickly to try to find a commit from a while back.

like image 888
Michael Plautz Avatar asked Sep 06 '25 03:09

Michael Plautz


1 Answers

You can use git log with various switches as explained by the git-log docs e.g.:

All commits whose message contains the text "xyz" will be:

git log --grep=xyz

--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 commits done by user [email protected] will be:

git log [email protected]

--author=<pattern> --committer=<pattern> Limit the commits output to ones with author/committer header lines that match the specified pattern (regular expression). With more than one --author=<pattern>, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=<pattern>).

and so on based on the git-log docs.

like image 160
Karol Dowbecki Avatar answered Sep 08 '25 00:09

Karol Dowbecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!