4

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 person@company.com
  • 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.

Michael Plautz
  • 3,578
  • 4
  • 27
  • 40
  • Mostly using `git log` arguments like [this](https://stackoverflow.com/questions/746684/how-to-search-through-all-git-and-mercurial-commits-in-the-repository-for-a-cert) and [this](https://stackoverflow.com/questions/2954477/how-to-find-commits-by-a-specific-user-in-git). If you read the [docs](https://git-scm.com/docs/git-log) for `git log` you'll see there are lots of such options – Cory Kramer Mar 20 '18 at 19:18

1 Answers1

6

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 person@company.com will be:

git log --author=person@company.com

--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.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111