用 git log -S(Pickaxe)查找改动

定位引入或删除某段代码的提交。

macOS搜索Git命令行低风险
运行 git log -S "文本",列出改动该文本出现次数的提交。

01命令

命令
$ git log -S "retry" --oneline -- src/

02作用说明

Pickaxe 搜索能回答“这个函数或配置何时出现”,排查回归和理解历史时非常有用。配合路径限制和 -G 正则搜索,在大仓库上也精确快速。

03风险

风险低风险
使用条件Git 2.20+ (install with Homebrew or Xcode Command Line Tools)
系统兼容性macOS with Git installed (Homebrew or Xcode Command Line Tools)
!注意: Pickaxe 会扫描差异,超长历史可能较慢;请用路径或日期范围缩小。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • git-log documentation
    Git · vendor-doc · 2026-09-20
    依据: Documents the -S pickaxe option, which finds commits changing the number of matches.

最后验证: 2026-10-13 · 分类: 开发者

06相关方案