文章目录
1. shell脚本工具目的说明
该shell脚本完成的工具的目的是输出指定时间段的指定作者在指定几个git库的提交记录,以便在遇到项目发布的时候可以快速通过修改差异进行相关的功能波及分析,最终确保相关的验证工作的完整性,无遗漏,保证版本的质量。
2.脚本使用
2.1 脚本使用说明
该脚本实现了指定日期段下,指定作者列表和指定git库列表生成详细的git入库记录到指定的文件中。以下几个在脚本具体实现逻辑中出现的变量需要在实际使用过程中进行修改:
after_date 设置提交时间的起始日期(包括当日)
until_date 设置提交时间的结束日期(包括当日)
save_file_path 设置git show的所有结果文件的目录路径
base_git_path 设置git库的基础目录路径
git_repositories 设置需要查询的git库名称的数组(这里要求所有的git库在同一个目录下)
author_list 设置需要查询的作者数组
file_path=$save_file_path/record.txt 设置git show所有结果的保存到的详细文件路径
其他说明:
after_date until_date两个日期执行脚本的时候,接收从控制台命令行上输入参数,例如:sh generateLog.sh 2022-09-21 2022-09-22
2.2 脚本实现逻辑
文件名:generateLog.sh
#!/bin/sh
function write_to_file_of_author {
echo "******作者:$1*****" | tee -a $file_path
for git_repository in ${git_repositories[@]};do
cd "$base_git_path/$git_repository"
echo "--------------git库名称:$git_repository---------------" | tee -a $file_path
for hash_committer in `git log --author="$1" --pretty=tformat:'%H' --after=="$after_date" --until=="$until_date"`;do
git show $hash_committer >> $file_path
#git show $hash_committer >> $file_path
echo $hash_committer
done
done
}
after_date="2022-09-21"
until_date="2022-09-22"
save_file_path="/f/mytool" #导出文件的记录目录,可以按需修改
echo $#
if [ $# -gt 1 ]; then
after_date=$1
until_date=$2
fi
echo $after_date
echo $until_date
file_path=$save_file_path/record.txt #git入库记录导出的文件路径,可以按需修改
if [ ! -f "$file_path" ]; then
touch $file_path
else
> $file_path
#rm -f $file_path
fi
base_git_path="/f" #git库的基础路径,需要按需修改
git_repositories=("spring-boot" "spring-boot")#git库名称,需要按需修改
author_list=("Stephane Nicoll" "Andy Wilkinson");#作者名称,需要按需修改
for ((i=0;i<${#author_list[@]};i++));do
echo ${author_list[i]}
write_to_file_of_author "${author_list[i]}"
done
echo "---end---"
2.3 通过结合tag创建的具体时间,达到抽取指定的2个tag之间的入库记录
该命令执行后查询得到具体的tag创建时间。
git log --tags --simplify-by-decoration --pretty=“format:%ai %d” |grep xxxtag
通过查询到的时间来确定上面shell脚本中的after_date until_date两个日期,据此2个的日期得到的导出的git show的record.txt文件,看该文件的时候再通过上面的tag的具体时分秒的时间来准确过滤相关的入库记录。
3.依赖的几条关键git命令
git log --all --format=‘%aN <%cE>’ | sort -u //列出所有历史的作者
git log --tags --simplify-by-decoration --pretty=“format:%ai %d” //查询所有tag创建时间
git log --author=‘Stephane Nicoll’ --pretty=tformat:‘%H,%aN,%ce,%cd,%s’ --after==‘2022-09-20’ --until==‘2022-09-22’ //查询指定的作者指定日期段的入库记录
git show 50040bd74824ea2d7a0cb63c994f260cc8e1d64b //查看指定commit id的修改内容