SQL|Askgit:利用熟悉的SQL语句挖掘git仓库的信息( 二 )
提交次数只有79次。
最频繁的提交者
按提交者分组author_name并按提交者排序。
askgit ''select count(*) as count, author_name from commits group by author_name having count > 1 order by count desc''
文章图片
按月提交统计
可以使用sqlite日期函数查看项目随时间的活动。可以看到,一开始有很多活动,并且活动逐渐减少。
askgit ''select strftime(''%Y-%m'', author_when) as 'month',
count(*) as total_commits, sum(additions), sum(deletions)
from commits group by strftime(''%Y-%me'', author_when) order by strftime(''%Y-%m'', author_when);''
文章图片
项目才两个月,上个月提交了71次,增加了4584行代码,删除了1315行代码。这个月只有一次,增加和删除的代码分别为254和136。
作者提交日历表
askgit ''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''
文章图片
标签
标签在git中可以很大程度上表示版本的发布,根据标签信息可以查看项目发版情况。
获取标签列表
在这里,可以看到该项目的标签列表。
askgit ''select name, tagger_name, target_type from tags''
文章图片
如果target_type是NULL这意味着它是一个轻量级的标签,并没有提交与它相关联。大多数情况下,人们会进行提交,并且由于提交具有日期,因此可以更轻松地进行关联。
标签的创建者和时间
下面的sql语句可以找出谁创建了标签以及对应的消息是什么。
askgit ''select name, commits.id, commits.message, author_name, author_email, author_when from tags, commits where tags.target_type = commits.id order by author_when''
找出开始和结束日期
可以根据创建标签的时间戳询问以上所有问题。这将使我们对这段时间内项目的进展情况有所了解。让我们创建一个简单的CSV文件,以便更轻松地提出这些问题。
askgit ''select name, commits.id, author_when from tags, commits where tags.target_type = commits.id order by author_when'' --format csv > tags.csv
下面脚本为每个标签都有开始时间和结束时间。以初始提交作为开始时间,然后使用之前的标记。
PREV_DATE=$(askgit ''select min(author_when) as first from commits'' --format csv |grep -v first)
while IFS=, read -r tag id date; do
if [[ ''$tag'' != ''name'' ]]; then
echo ${tag},${id},${PREV_DATE},${date}
PREV_DATE=${date}
fi
done < tags.csv >tag-timess.csv
标签统计
通过遍历该文件,并为每个标记提取一些统计信息。
while IFS=, read -r tag id start end; do
echo $tag
askgit ''select count(*) as count from commits where author_when > '${start}' and author_when <= '${end}''' --format json | jq .count
askgit ''select count(*) as count, author_name from commits where author_when > '${start}' and author_when <= '${end}' group by author_name order by count desc''
done < tag-timess.csv
文件
askgit中有一个file表,该表显示了特定提交时的存储库状态,因此对于实际跟踪在提交中或两次提交之间发生的更改没有太大用处。最好使用git diff-tree和git log查找相关的信息。
使用特定提交修改的文件
可以看到在最新提交中更改了哪些文件:
git diff-tree --no-commit-id -r --name-only HEAD^1
标签修改的文件
我们可以使用..指定提交范围的方式,因此让我们看一下在v1.5.0和之间哪些文件已更改v1.7.0。
git diff-tree --no-commit-id -r --name-only v1.5.0..v1.7.0
推荐阅读
- 时间表|2021考研:怎么严格利用自己的考研时间表?
- 法制|利用虚假微信支付骗钱?警方将这一诈骗团伙打掉
- 悉知|悉知科技深化制造企业线上引流,利用数字化驱动业绩增长
- 乌兹别克斯坦|乌兹别克斯坦将利用外资推进电影行业市场化
- Lightning接口|苹果不愿屈服于Type-C,利用磁吸or无线充电正面反击?
- 许佳琪|利用戴燕妮,打压许佳琪《青春有你2》请对漂亮姐姐好一点
- 利用小孩子做掩护!这对姐妹花竟在杭州一超市里做出这种事...
- 自卖自买利用“快递保价”诈骗 还“收徒”传授“致富经”
- 钟某某|福建一学校校长被指利用职权猥亵女教师,教育局:停职调查
- 国家文物局印发大遗址利用导则|国家文物局印发大遗址利用导则 提升文物保护管理水平
