You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用git grep查找仓库中文件文本新增指定单词的提交

Find Git Commits Where "introduced" Was Added to File Content (Not Commit Messages)

Got it, let's break down how to track down exactly those commits you're looking for—where the word "introduced" was added to actual file content, and we'll explicitly exclude any commits where that word shows up in the commit message itself.

The Core Command

Here's the one-liner that hits all your requirements:

git log -S"\bintroduced\b" --pickaxe-regex --no-merges --invert-grep --grep="introduced"

Let's break down what each part does so you understand why it works:

  • -S"\bintroduced\b" --pickaxe-regex: This uses Git's "pickaxe" feature to hunt for commits where the occurrence count of the word "introduced" changed (i.e., it was added or removed). The \b ensures we match the whole word, so we don't pick up partial matches like "reintroduced". --pickaxe-regex lets us use regex for precise word matching.
  • --no-merges: Skips merge commits, which often bring in changes from other branches and can clutter your results with unrelated additions.
  • --invert-grep --grep="introduced": --grep checks commit messages for the word, and --invert-grep flips that to exclude any commits where "introduced" appears in the message itself.

See the Actual Added Lines

If you want to see exactly which lines in which files added the word "introduced", add the -p flag to show the full diff for each matching commit:

git log -p -S"\bintroduced\b" --pickaxe-regex --no-merges --invert-grep --grep="introduced"

Narrow It Down Further

  • Filter by file type: If you only care about specific files (e.g., Python scripts), add a path filter at the end:
    git log -p -S"\bintroduced\b" --pickaxe-regex --no-merges --invert-grep --grep="introduced" -- '*.py'
    
  • Case insensitivity: If you want to match "Introduced" or "INTRODUCED" too, adjust the regex and add the -i flag to the commit message check:
    git log -p -S"\b[Ii]ntroduced\b" --pickaxe-regex --no-merges --invert-grep --grep="introduced" -i
    

Hope this gives you exactly the targeted results you need—no generic grep hacks here, just Git-specific tools tailored to your request.

内容的提问来源于stack exchange,提问作者There is nothing we can do

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:23:16