git log根据特定条件查询日志并统计修改的代码行数(5)
$ git log -10 --oneline 7bf665f12 (HEAD -> 6.0, tag: 6.0.6, origin/6.0) Redis 6.0.6. a5696bdf4 Run daily CI on PRs to release a branch e15528bf1 Adds SHA256SUM to redis-stable tarball upload e28aa99af Support passing stack allocated module strings to moduleCreateArgvFromUserFormat (#7528) 305143004 Send null for invalidate on flush (#7469) 29b20fd52 Notify systemd on sentinel startup (#7168) 5b3668121 Add registers dump support for Apple silicon (#7453) 0f75036c0 correct error msg for num connections reaching maxclients in cluster mode (#7444) b1a01fda9 Fix command help for unexpected options (#7476) 83f55f61a Refactor RM_KeyType() by using macro. (#7486) 显示每条记录中文件修改的具体行数和行体统计 使用 --stat 参数就可以显示每条记录的中修改文件的具体行数和行数统计 $ git log -2 --stat commit 7bf665f125a4771db095c83a7ad6ed46692cd314 (HEAD -> 6.0, tag: 6.0.6, origin/6.0) Author: Oran Agra <oran@redislabs.com> Date: Sun Jul 19 14:00:20 2020 +0300 Redis 6.0.6. 00-RELEASENOTES | 245 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/help.h | 4 +- src/version.h | 2 +- 3 files changed, 248 insertions(+), 3 deletions(-) commit a5696bdf4f2687ab45f633ccb7cdc4ee9c2f957d Author: Oran Agra <oran@redislabs.com> Date: Sun Jul 19 15:33:21 2020 +0300 Run daily CI on PRs to release a branch .github/workflows/daily.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 显示每条提交记录中文件的增加行数和删除行数 使用 --numstat 参数会把 --stat 参数中合并显示的修改行数拆分成增加行数和删除行数 $ git log -2 --numstat commit 7bf665f125a4771db095c83a7ad6ed46692cd314 (HEAD -> 6.0, tag: 6.0.6, origin/6.0) Author: Oran Agra <oran@redislabs.com> Date: Sun Jul 19 14:00:20 2020 +0300 Redis 6.0.6. 245 0 00-RELEASENOTES 2 2 src/help.h 1 1 src/version.h commit a5696bdf4f2687ab45f633ccb7cdc4ee9c2f957d Author: Oran Agra <oran@redislabs.com> Date: Sun Jul 19 15:33:21 2020 +0300 Run daily CI on PRs to release a branch 4 2 .github/workflows/daily.yml 依次罗列各提交记录中每个文件中增加的行数和删除的行数 要想达到这个目的需要用到 --prety=tformat: --numstat 参数,这样的显示格式便于统计 $ git log -2 --pretty=tformat: --numstat 245 0 00-RELEASENOTES 2 2 src/help.h 1 1 src/version.h 4 2 .github/workflows/daily.yml 统计修改的代码行数 有了前面的铺垫,想要统一修改的行数就容易了,只要配合 awk 工具就可以完成统计了 $ $ git log -2 --pretty=tformat: --numstat | awk '{adds += $1; subs += $2; diffs += $1 - $2} END {printf "added lines: %s removed lines: %s, diff lines: %s\n", adds, subs, diffs}' added lines: 252 removed lines: 5, diff lines: 247 还可以统计两个分支相差的代码行数 $ git log 6.0..unstable --pretty=tformat: --numstat | awk '{adds += $1; subs += $2; diffs += $1 - $2} END {printf "added lines: %s removed lines: %s, diff lines: %s\n", adds, subs, diffs}' added lines: 5 removed lines: 2, diff lines: 3 到这里可以发现前面的知识都可以用上,前面筛选的参数变了,得到的结果就变了,我们可以根据需求来调整不同的参数 总结 git log 就是一部代码库记录的“史书”,对于曾经所做的修改可以做到有史可查 git log 的选项参数可以分为筛选参数和格式参数,筛选参数可以选择记录范围,格式参数可以控制显示样式 统计就是按照一定规律来将数据进行汇总,在进行汇总前需要将数据进行整理,这样汇总的工作才会更加顺利 到此这篇关于git log根据特定条件查询日志并统计修改的代码行数的文章就介绍到这了,更多相关git log统计修改代码行数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! (编辑:ASP站长网) |