Crates.io | git-query |
lib.rs | git-query |
version | 0.3.0 |
source | src |
created_at | 2024-02-15 02:47:13.391569 |
updated_at | 2024-02-24 19:49:54.128166 |
description | Run SQL against git history |
homepage | https://github.com/MatthewFay/git-query |
repository | https://github.com/MatthewFay/git-query |
max_upload_size | |
id | 1140612 |
size | 60,537 |
git-query
is a powerful command-line tool designed for querying and analyzing the commit history of a Git repository using SQL.
Ensure that you have Rust installed on your system. Then, install git-query
using the following command:
cargo install git-query
git-query
This will initiate the program and execute an initial SQL query, displaying the latest commit for the repository.SELECT * FROM commits WHERE date BETWEEN '2022-01-01 00:00:00 UTC' AND '2022-12-31 23:59:59 UTC';
exit
To load additional commit history from a commit that is not present (e.g., a commit in another branch), you can use the traverse
command: traverse <commit id>
.
If you only want commit history for a particular branch, navigate to that branch (using git checkout
) before running git-query
.
See below for information on the SQL tables that can be queried, and the data within.
id
: Commit idauthor
: Author of the commitdate
: Datetime of the commitmessage
: Commit messagename
: Branch nametype
: Branch type (either remote or local)head_commit_id
: HEAD commit idhead_commit_date
: Datetime of HEAD commitid
: Tag idname
: The tag nametarget_id
: The tag target id (e.g., commit id)target_type
: The type of target (e.g., commit)tagger
: Who created the tagdate
: Datetime of the tagmessage
: The tag message. Any PGP signatures are removedThese queries use the serde repo.
>> SELECT * FROM commits ORDER BY date DESC LIMIT 1;
┌─────────┬──────────────┬─────────────────────────┬───────────────────────────┐
│ id ┆ author ┆ date ┆ message │
╞═════════╪══════════════╪═════════════════════════╪═══════════════════════════╡
│ 1d54973 ┆ David Tolnay ┆ 2024-02-13 03:49:34 UTC ┆ Merge pull request #2697 │
│ ┆ ┆ ┆ from nyurik/format-str │
│ ┆ ┆ ┆ │
│ ┆ ┆ ┆ A few minor `write_str` │
│ ┆ ┆ ┆ optimizations │
└─────────┴──────────────┴─────────────────────────┴───────────────────────────┘
Rows returned: 1
>> SELECT DISTINCT(author) FROM commits ORDER BY author LIMIT 5;
┌───────────────────┐
│ author │
╞═══════════════════╡
│ Adam Crume │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Adam H. Leventhal │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Alex │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Alex Crichton │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ Alex Shapiro │
└───────────────────┘
Rows returned: 5
>> SELECT * FROM commits WHERE author = 'Adam Crume' ORDER BY date DESC LIMIT 1;
┌─────────┬────────────┬─────────────────────────┬─────────────────────────────┐
│ id ┆ author ┆ date ┆ message │
╞═════════╪════════════╪═════════════════════════╪═════════════════════════════╡
│ 05e931b ┆ Adam Crume ┆ 2018-06-03 04:11:42 UTC ┆ Update tests and use quote! │
│ ┆ ┆ ┆ macro │
│ ┆ ┆ ┆ │
└─────────┴────────────┴─────────────────────────┴─────────────────────────────┘
Rows returned: 1
>> SELECT COUNT(*) FROM commits;
┌──────────┐
│ COUNT(*) │
╞══════════╡
│ 3908 │
└──────────┘
Rows returned: 1
>> SELECT * FROM commits WHERE message LIKE '%quote! macro%'
┌─────────┬────────────┬─────────────────────────┬─────────────────────────────┐
│ id ┆ author ┆ date ┆ message │
╞═════════╪════════════╪═════════════════════════╪═════════════════════════════╡
│ 05e931b ┆ Adam Crume ┆ 2018-06-03 04:11:42 UTC ┆ Update tests and use quote! │
│ ┆ ┆ ┆ macro │
│ ┆ ┆ ┆ │
└─────────┴────────────┴─────────────────────────┴─────────────────────────────┘
Rows returned: 1
>> SELECT * FROM commits WHERE date BETWEEN '2021-01-20 00:00:00 UTC' AND '2021-01-21 00:00:00 UTC';
┌─────────┬───────────────┬─────────────────────────┬──────────────────────────┐
│ id ┆ author ┆ date ┆ message │
╞═════════╪═══════════════╪═════════════════════════╪══════════════════════════╡
│ b276849 ┆ Jonas Bushart ┆ 2021-01-20 19:41:45 UTC ┆ Prevent panic when │
│ ┆ ┆ ┆ deserializing malformed │
│ ┆ ┆ ┆ Duration │
│ ┆ ┆ ┆ │
│ ┆ ┆ ┆ std::time::Duration::new │
│ ┆ ┆ ┆ can panic. There is no │
│ ┆ ┆ ┆ alternative non-panicing │
│ ┆ ┆ ┆ constructor. │
│ ┆ ┆ ┆ Check the panic │
│ ┆ ┆ ┆ condition beforehand and │
│ ┆ ┆ ┆ return an error instead │
│ ┆ ┆ ┆ of panicing. │
│ ┆ ┆ ┆ │
│ ┆ ┆ ┆ Fixes #1933 │
│ ┆ ┆ ┆ │
└─────────┴───────────────┴─────────────────────────┴──────────────────────────┘
Rows returned: 1
>> SELECT * FROM branches ORDER BY head_commit_date DESC;
┌───────────────┬────────┬────────────────┬─────────────────────────┐
│ name ┆ type ┆ head_commit_id ┆ head_commit_date │
╞═══════════════╪════════╪════════════════╪═════════════════════════╡
│ master ┆ local ┆ 1d54973 ┆ 2024-02-13 03:49:34 UTC │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ origin/HEAD ┆ remote ┆ 1d54973 ┆ 2024-02-13 03:49:34 UTC │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ origin/master ┆ remote ┆ 1d54973 ┆ 2024-02-13 03:49:34 UTC │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ origin/watt ┆ remote ┆ af31449 ┆ 2022-07-02 00:56:18 UTC │
└───────────────┴────────┴────────────────┴─────────────────────────┘
Rows returned: 4
>> SELECT * FROM tags ORDER BY DATE DESC LIMIT 1;
┌─────────┬──────────┬───────────┬───────────┬───────────┬──────────┬──────────┐
│ id ┆ name ┆ target_id ┆ target_ty ┆ tagger ┆ date ┆ message │
│ ┆ ┆ ┆ pe ┆ ┆ ┆ │
╞═════════╪══════════╪═══════════╪═══════════╪═══════════╪══════════╪══════════╡
│ 9ed62c3 ┆ v1.0.196 ┆ ede9762 ┆ commit ┆ David ┆ 2024-01- ┆ Release │
│ ┆ ┆ ┆ ┆ Tolnay ┆ 26 ┆ 1.0.196 │
│ ┆ ┆ ┆ ┆ ┆ 22:00:35 ┆ │
│ ┆ ┆ ┆ ┆ ┆ UTC ┆ │
└─────────┴──────────┴───────────┴───────────┴───────────┴──────────┴──────────┘
Rows returned: 1
>> SELECT commits.*, tags.id AS tag_id, tags.date AS tag_date, tags.message AS tag_message FROM commits INNER JOIN tags ON commits.id = tags.target_id ORDER BY tags.date DESC LIMIT 1;
┌─────────┬───────────┬───────────┬───────────┬─────────┬───────────┬──────────┐
│ id ┆ author ┆ date ┆ message ┆ tag_id ┆ tag_date ┆ tag_mess │
│ ┆ ┆ ┆ ┆ ┆ ┆ age │
╞═════════╪═══════════╪═══════════╪═══════════╪═════════╪═══════════╪══════════╡
│ ede9762 ┆ David ┆ 2024-01-2 ┆ Release ┆ 9ed62c3 ┆ 2024-01-2 ┆ Release │
│ ┆ Tolnay ┆ 6 ┆ 1.0.196 ┆ ┆ 6 ┆ 1.0.196 │
│ ┆ ┆ 22:00:35 ┆ ┆ ┆ 22:00:35 ┆ │
│ ┆ ┆ UTC ┆ ┆ ┆ UTC ┆ │
└─────────┴───────────┴───────────┴───────────┴─────────┴───────────┴──────────┘
Rows returned: 1
This project is licensed under either of
at your option.