加入收藏 | 设为首页 | 会员中心 | 我要投稿 济源站长网 (https://www.0391zz.cn/)- 数据工具、数据仓库、行业智能、CDN、运营!
当前位置: 首页 > 服务器 > 安全 > 正文

git log根据特定条件查询日志并统计修改的代码行数

发布时间:2020-09-21 18:29:34 所属栏目:安全 来源:网络整理
导读:这篇文章主要介绍了git log根据特定条件查询日志并统计修改的代码行数,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参

$ git log -2 arm commit 7329cc39818a05c168e7d1e791afb03c089f1933 (origin/arm, arm) Author: Salvatore Sanfilippo <antirez@gmail.com> Date: Sun Feb 19 15:07:08 2017 +0000 ARM: Avoid fast path for BITOP. GCC will produce certain unaligned multi load-store instructions that will be trapped by the Linux kernel since ARM v6 cannot handle them with unaligned addresses. Better to use the slower but safer implementation instead of generating the exception which should be anyway very slow. commit 4e9cf4cc7ed4b732fc4bb592f19ceb41d132954e Author: Salvatore Sanfilippo <antirez@gmail.com> Date: Sun Feb 19 15:02:37 2017 +0000 ARM: Use libc malloc by default. I'm not sure how much test Jemalloc gets on ARM, moreover compiling Redis with Jemalloc support in not very powerful devices, like most ARMs people will build Redis on, is extremely slow. It is possible to enable Jemalloc build anyway if needed by using "make MALLOC=jemalloc".

其实在 git 体系中,分支名、commit、标签等拥有几乎相同的含义,所以在很多场景下可以扩展互换,比如 git log 后面加上分支名就可以查询指定分支的提交记录,如果加上 commit 就会查询这个 commit 之前的提交记录,如果加上标签,就可以查询这个标签之前的提交记录,比如我们加一个 commit 试试:

$ git log -2 7329cc39818a05c168e7d1e791afb03c089f1933 commit 7329cc39818a05c168e7d1e791afb03c089f1933 (origin/arm, arm) Author: Salvatore Sanfilippo <antirez@gmail.com> Date: Sun Feb 19 15:07:08 2017 +0000 ARM: Avoid fast path for BITOP. GCC will produce certain unaligned multi load-store instructions that will be trapped by the Linux kernel since ARM v6 cannot handle them with unaligned addresses. Better to use the slower but safer implementation instead of generating the exception which should be anyway very slow. commit 4e9cf4cc7ed4b732fc4bb592f19ceb41d132954e Author: Salvatore Sanfilippo <antirez@gmail.com> Date: Sun Feb 19 15:02:37 2017 +0000 ARM: Use libc malloc by default. I'm not sure how much test Jemalloc gets on ARM, moreover compiling Redis with Jemalloc support in not very powerful devices, like most ARMs people will build Redis on, is extremely slow. It is possible to enable Jemalloc build anyway if needed by using "make MALLOC=jemalloc".

因为 commit id 就是之前的 arm 分支最新的记录,所以这个命令等价于 git log -2 arm

查询指定 commit 之间的提交记录

如果想查询两个 commit 之前的提交记录,可以将两个 commit id 依次放在命令后面并用 .. 连接就可以了,格式为 git log commit1..commit2,需要注意的是这样查询出来的提交记录列表中不包含 commit1,其实列举出的就是 commit1 之后又做了哪些修改提交。

$ git log e15528bf1da1f1232fd08801ad382c915be94662..7bf665f125a4771db095c83a7ad6ed46692cd314 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. 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

这个特性有一个应用就是在 merge 分支之前可以查询究竟会 merge 哪些记录,常见的用法比如 git log feature..dev 就是列举出 feature 分支合并到 dev 分支将要合并的提交记录有哪些。

$ git log 6.0..unstable commit 324e22accf457edc996971bc97f5474349cd7c4c (unstable) Author: antirez <antirez@gmail.com> Date: Fri Dec 20 12:29:02 2019 +0100 Fix ip and missing mode in RM_GetClusterNodeInfo().

查询指定文件的提交记录

查询指定文件的提交记录一般直接在 git log 命令后面跟上文件名就可以,但是为了避免和分支名产生分歧,所以通常在文件名前面加上 -- 用来区分,-- 这个标识符就是用来防止混淆的,放在 -- 前面的是分支名,放在后面的是文件名,相同的作用不仅仅在 git log 命令中,在其他命令比如 git checkout 中也有相同的用法。

$ git log -2 -- redis.conf commit 7a536c2912be1fd9f62b26b7022a00644c88ef8b Author: Yossi Gottlieb <yossigo@users.noreply.github.com> Date: Fri Jul 10 11:33:47 2020 +0300 TLS: Session caching configuration support. (#7420) * TLS: Session caching configuration support. * TLS: Remove redundant config initialization. (cherry picked from commit 3e6f2b1a45176ac3d81b95cb6025f30d7aaa1393) commit 8312aa27d47c0befcf69eb74d0a5dc19745ffd32 Author: antirez <antirez@gmail.com> Date: Mon Jun 22 11:21:21 2020 +0200 Clarify maxclients and cluster in conf. Remove myself too. (cherry picked from commit 59fd178014c7cca1b0c668b30ab0d991dd3030f3)

显示格式

git log 除了可以筛选提交记录,还可以控制显示格式,普通不加参数,会显示作者、邮件、提交描述信息、日期等信息。

通过添

$ git log -1 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.

加参数可以控制和改变显示格式,下面来看几条常见的

显示单行信息

git log 默认会显示多行信息,使用 --oneline 后每条提交记录只显示一行信息,可以在一屏幕中查看到更多的信息

(编辑:济源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读