如何查找包含特定词汇的Git提交信息?含wordA与wordB多词查询方法
Git Commit History Search: Target Specific Terms & Combined Matches
Hey there! Let’s walk through the exact Git commands you need to tackle both of your commit search scenarios.
1. Find commits containing a specific term in their message
To locate commits where the commit message includes a particular word or phrase, use Git’s --grep flag with git log:
git log --grep="your-target-term"
- Add
-iif you want a case-insensitive search (so "Term" and "term" both count):git log --grep="your-target-term" -i - Use
--onelinefor condensed, easier-to-scan output (shows only the commit hash and short message):git log --grep="your-target-term" --oneline
2. Find commits with both wordA AND wordB in their message
By default, multiple --grep flags will match commits that have either term. To enforce an AND condition (both terms must appear in the same commit message), add the --all-match flag:
git log --grep="wordA" --grep="wordB" --all-match
You can combine this with the same convenience flags as before:
git log --grep="wordA" --grep="wordB" --all-match -i --oneline
Bonus: Search code changes (not just commit messages)
If you ever need to find commits where the actual code includes your target terms (not just the commit message), use git log -S:
# Find commits where wordA was added/removed in code git log -S"wordA" # Find commits with both wordA AND wordB in code changes git log -S"wordA" -S"wordB" --all-match
内容的提问来源于stack exchange,提问作者Druudik
相关产品推荐
相关产品推荐

