git搜索历史上曾经的文本内容

文章目录

问题

我们知道,github有文本搜索功能:

比如想搜哪些文件内容包括 aaa ,在搜索框中输入 aaa

但是,如果是历史上曾经有过的文本,这个办法貌似不行。

比如文件 test.txt ,历史上曾经包含了 aaa 文本,但是后来修改过文件,当前的文件里已经不包含 aaa 文本了。此时在github里就搜不到了:

该怎么搜索呢?

在命令行搜索历史内容

可以通过git命令行来搜索历史内容。

比如要搜索 aaa ,通过 grep 命令,可知搜不到:

powershell 复制代码
➜  test0402 git:(main) grep -r aaa .
➜  test0402 git:(main)

使用以下命令搜索:

powershell 复制代码
git log -S'aaa' -p

结果如下:

powershell 复制代码
commit 4daf5988f299e711fb821dc956b9463c27400052 (HEAD -> main, origin/main, origin/HEAD)
Author: dukeding <kaiding@cn.ibm.com>
Date:   Fri Mar 8 14:15:19 2024 +0800

    Update test.txt

diff --git a/test.txt b/test.txt
index 90d2f06..2975aa0 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-test aaa test
+test bbb test

commit d77ab62652abeb1a06eddd7f7cf76ed7720e8b97
Author: dukeding <kaiding@cn.ibm.com>
Date:   Fri Mar 8 14:10:24 2024 +0800

    Create test.txt

diff --git a/test.txt b/test.txt
new file mode 100644
index 0000000..90d2f06
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+test aaa test

可见,列出了 aaa 出现的commit,以及 aaa 消失的commit,这样就可以了解 aaa 的来龙去脉了。

参考

  • https://stackoverflow.com/questions/4705517/github-searching-through-older-versions-of-files
相关推荐
无心水3 小时前
【Hermes:安全、权限与生产环境】39、智能体也会犯错?Hermes 纠错、回滚与遗忘机制全指南 —— 让 AI 的错误像 Git 一样可逆可控
人工智能·git·安全·mcp协议·openclaw·hermes·honcho
南境十里·墨染春水8 小时前
linux学习进展 git详解
linux·git·学习
zhangfeng11338 小时前
CodeBuddy ai对话框上面的git docs terminal Rulds 干嘛用的,以thinkphp fastadmin 为例,插件市场
人工智能·git·编程
OYangxf9 小时前
Git Conflict Resolution
大数据·git·elasticsearch
高斯林.神犇9 小时前
Git全套流程
git
次元工程师!11 小时前
LangFlow开发(一)—安装和部署
git·python·大模型·langflow
怣疯knight12 小时前
【无标题】
git
Jim-zf12 小时前
git 锁文件
git
lcx_defender12 小时前
Git常见操作与指令
git
一只积极向上的小咸鱼1 天前
嵌套 Git 仓库 / gitlink / submodule 问题总结
大数据·git·elasticsearch