【Git 学习笔记】gitk 命令与 git log 其他参数的使用

news/2024/7/7 20:14:22 标签: git, 学习, 笔记

gitk__0">1.7 用 gitk 查看提交历史

# make sure you have gitk installed
$ which gitk
/usr/bin/gitk
# Sync the commit ID
$ git checkout master && git reset --hard 13dcad
# bring up the gitk interface, --all to see everything
$ gitk --all &

实测结果:
在这里插入图片描述


1.8 在历史版本中查找 commit 版本

# look at the entire history and search every commit that has "Performance" in its commit message:
$ git log --grep "Performance" --oneline --all

上述命令查找 Git 库内所有分支、所有提交注释中,包含 Performance 字样的 commit 版本,并单行显示。注意,这里的 --grep 参数是 区分 大小写的。

此外,也可以在 gitk 命令中查找指定关键字,gitk 会自动高亮匹配:

在这里插入图片描述

1.9 在历史版本的代码中搜索信息

有时候,仅仅在提交注释中进行检索并不能满足实际工作需要,比如要定位哪些提交版本改动了某个方法或变量时,就需要借助 git log 的其他参数实现了。

练习:以 JGit 项目为例,找出满足以下条件的所有提交版本信息:

  1. SHA-1 指定为 b14a939
  2. 变更的一行中包含 "isOutdated" 方法
  3. 单行显示结果

执行命令如下:

$ git checkout master && git reset --hard b14a939
$ git log -G "isOutdated" --oneline
c9e4a7855 Add isOutdated method to DirCache
797ebba30 Add support for getting the system wide configuration
4c14b7623 Make lib.Repository abstract and lib.FileRepository its implementation
c9c57d34d Rename Repository 'config' as 'repoConfig'
5c780b387 Fix unit tests using MockSystemReader with user configuation
cc905e7d4 Make Repository.getConfig aware of changed config

参数 -G 实现的是在 文件变更的增量补丁 中查找。只要提交的版本中,某一行代码新增或删除过包含关键词 isOutdated 的情况,就会被检索到。

与之类似的另一个参数是 -S,其唯一区别在于,-S 检索的是指定关键词在某版本中的 出现次数 的变化情况。对比 -S 的执行结果:

$ git checkout master && git reset --hard b14a939
$ git log -S "isOutdated" --oneline
c9e4a7855 Add isOutdated method to DirCache
797ebba30 Add support for getting the system wide configuration
4c14b7623 Make lib.Repository abstract and lib.FileRepository its implementation
5c780b387 Fix unit tests using MockSystemReader with user configuation
cc905e7d4 Make Repository.getConfig aware of changed config

可以看到 commit ID 为 c9c57d34d 仅在 -G 时出现,在 -S 中未曾出现。借助命令 git show 查看该版本详情( grep -C4 会展示目标代码行前后各 4 行的情况):

$ git show c9c57d3 | grep -C4 "isOutdated"
@@ -417,14 +417,14 @@ public FileBasedConfig getConfig() {
                                throw new RuntimeException(e);
                        }
                }
-               if (config.isOutdated()) {
+               if (repoConfig.isOutdated()) {
                                try {
-                                       loadConfig();
+                                       loadRepoConfig();
                                } catch (IOException e) {

原来是对象的重命名导致的变更,导致这一行出现了关键词,但出现次数并不受影响。


http://www.niftyadmin.cn/n/5535032.html

相关文章

pycharm配置conda解释器

假如我新建了一个conda虚拟环境,名为python3.8

动态规划 剪绳子问题

给一段长度为n的绳子&#xff0c;请把绳子剪成m段&#xff0c;每段绳子的长度为k[0],k[1],k[2],k[3]....k[m].请问k[0]k[1]k[2].....*k[m]的最大乘积为多少 #include <vector> // 包含vector头文件 #include <algorithm> // 包含algorithm头文件&#xff0c;用于m…

阿里云centos 7.9 使用宝塔面板部署.netcore 6.0

前言&#xff1a; 在做工作之前之前&#xff0c;如果你的服务器有数据盘&#xff0c;而且又没挂载&#xff0c;但是你想使用数据盘做为工作目录&#xff0c;建议跳转到下面这个链接先挂载数据盘&#xff0c;并到数据盘创建好目录&#xff0c;修改站点工作目录到数据盘的目录&am…

【GIT】git如何合并其他分支的部分代码

git如何合并其他分支的部分代码 在Git中&#xff0c;如果你想要合并其他分支的特定代码到你的当前分支&#xff0c;你可以使用git cherry-pick命令。这个命令允许你选择一个或多个提交&#xff08;commits&#xff09;并将它们应用到你当前的分支。 以下是使用git cherry-pic…

使用EndNote在Word中插入参考文献,并编辑参考文献样式方法

一、背景 在准备中期报告时&#xff0c;学校给的是Word模板&#xff0c;习惯了Latex排版和添加参考文献的便利后&#xff0c;真不想用word写东西。 之前投《机器人》期刊&#xff08;被拒了&#xff09;和准备开题的时候也是用word写的&#xff0c;当时为方便添加参考文献和定…

batchNorm 和layernorm的区别

Batch Normalization (BN) Batch Normalization (BN) 是一种在深度学习中常见的技术&#xff0c;它通过对每一批数据的特征进行归一化处理&#xff0c;使得每一层的输入数据分布趋于稳定&#xff0c;从而加速网络的收敛速度并提高模型的泛化能力。BN的主要特点包括&#xff1a…

关于 lvds 屏幕的一些知识

网上的截图&#xff1a; lvds的 通道。 lvds 的协议 关于 sync 模式与 de 模式&#xff1a; ------------------------------------------------------------------------------------------------------------------ 芯片的数据手册的看法。 这个手册 &#xff0c;就指明了…

继承QAbstractListModel,结合QListView

这里想要写一个QAbstractListModel的子类&#xff0c;学习一下如何实例化QAbstractListModel。 QAbstractListModel子类化-CSDN博客 QVariant与自定义类型互转之奇巧淫技_qt 类型转 qvariant-CSDN博客 #pragma once#include <QStyledItemDelegate> #include <qmeta…