Michael Plautz
Michael Plautz

Reputation: 3778

How do I query the git commit history?

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:

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.

Upvotes: 4

Views: 3174

Answers (1)

Karol Dowbecki
Karol Dowbecki

Reputation: 44942

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.

Upvotes: 6

Related Questions