一、gitqlite能做些什么
用过git,也用过sql。两者结合起来用有试过吗?github上开源了gitqlite项目
github地址:https://github.com/augmentable-dev/gitqlite。该项目使用sql语法可以做以下事情:
- 列出所有的commit:
gitqlite “SELECT * FROM commits”
复制
- 列出所有作者的提交数量并排序:
SELECT author_email, count(*) FROM commits GROUP BY author_email ORDER BY count(*) DESC
复制
- 除开合并提交,再按所有作者的提交数量排序:
SELECT author_email, count(*) FROM commits WHERE parent_count < 2 GROUP BY author_email ORDER BY count(*) DESC
复制
- 某个提交id所变更的文件:
SELECT * FROM files WHERE commit_id='some_commit_id'
复制
- 按照短id查看变更文件:
SELECT * FROM files WHERE commit_id LIKE 'shortened_commit_id%'
复制
- 查看每位作者的变更行数,
SELECT count(*) AS commits, SUM(additions) AS additions, SUM(deletions) AS deletions, author_email FROM commits GROUP BY author_email ORDER BY commits
复制
- 查看作者每天的提交量:
SELECT count(*) AS commits, count(case when strftime('%w',author_when)='0' then 1 end) as sunday, count(case when strftime('%w',author_when)='1' then 1 end) as monday, count(case when strftime('%w',author_when)='2' then 1 end) as tuesday, count(case when strftime('%w',author_when)='3' then 1 end) as wednesday, count(case when strftime('%w',author_when)='4' then 1 end) as thursday, count(case when strftime('%w',author_when)='5' then 1 end) as friday, count(case when strftime('%w',author_when)='6' then 1 end) as saturday, author_email FROM commits GROUP BY author_email ORDER BY commits
复制
二、gitqlite怎么安装
那么怎么安装呢?首先该项目是个go程序,需要先安装go环境,并设置GOPATH变量
- 在centos7安装go,
yum install go
复制
- 设置GOPATH变量,
export GOPATH=/data/mariolu/gopath(这里是填你的个人目录)
复制
- 下载gitqlite,使用go get命令可以顺带下载依赖库,
go get -v github.com/augmentable-dev/gitqlite
复制
- 安装gitqlite,
go install -v -tags=sqlite_vtable github.com/augmentable-dev/gitqlite
复制
- 安装好的程序在$GOPATH/bin/gitqlite。并把$GOPATH/bin设置到二进制路径$PATH下
以后就可以愉快的使用gitqlite “sql语句”在git仓库目录下做历史提交的探索了。