2

git 版本管理中历史搜索

 7 months ago
source link: https://www.v2ex.com/t/1015315
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  问与答

git 版本管理中历史搜索

  jeesk · 4 小时 52 分钟前 · 284 次点击

开源项目的 commit 次数太多了, 我记得有些 commit 提交的代码关键字, 但是搜索了一下,没有找到能够搜索提交代码, 只能搜索 commit message , 大佬们有什么高招吗?

3 条回复    2024-02-11 15:59:36 +08:00
Dvel

Dvel      4 小时 32 分钟前

Fork 可以直接搜,侧边栏的放大镜,搜索内容选择 Diff Content 。
geelaw

geelaw      4 小时 29 分钟前

取决于你说的“提交的代码”是什么意思——严格来说每个 git commit 记住的是当时所有的文件,因此同一段代码通常会出现在数个 commits 里面,这大概不是楼主想要的。

如果是要搜索 diff patch text 里面的内容,可以用 git log 的 -G 。

如果你要找的代码片段存在于一个已知的 commit 里面,可以在那个 commit 上 git blame 那个代码文件,发现那段代码被 Git 认为最后一次修改的 commit 。
BlitheChiang

BlitheChiang      58 分钟前

op 提到的场景我之前也有碰到过,可以尝试这样的方法:假设你的代码片段是`$代码片段`,使用 `git log -S"$代码片段"` 可以搜索出关于提交内容中含有`$代码判断`的提交。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK