Claude-skill-registry gh-search-commits
Use when searching commit history across GitHub repositories - provides syntax for filtering by author, committer, dates, hashes, and merge commits with proper exclusion handling
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/gh-search-commits" ~/.claude/skills/majiayu000-claude-skill-registry-gh-search-commits && rm -rf "$T"
skills/data/gh-search-commits/SKILL.mdGitHub CLI: Search Commits
Overview
Search for commits across GitHub repositories using
gh search commits. Filter by author, committer, dates, commit hashes, and more.
When to Use This Skill
Use this skill when searching commits across GitHub:
- Finding commits by author or committer across repos/orgs
- Searching commit messages for keywords across repositories
- Filtering by commit dates or hashes in specific repos
- Looking for merge commits across an organization
- Searching in specific repositories or organizations
- Need to exclude certain results (requires
flag)--
Syntax
gh search commits [<query>] [flags]
Key Flags Reference
Author & Committer Filters
| Flag | Purpose | Example |
|---|---|---|
| Filter by author username | |
| Filter by author name | |
| Filter by author email | |
| Filter by authored date | |
| Filter by committer username | |
| Filter by committer name | |
| Filter by committer email | |
| Filter by committed date | |
Commit Attributes
| Flag | Purpose | Example |
|---|---|---|
| Filter by commit hash | |
| Filter by parent hash | |
| Filter by tree hash | |
| Filter merge commits only | |
Repository Filters
| Flag | Purpose | Example |
|---|---|---|
| Filter by repo owner | |
| Search in specific repo | |
| Filter by visibility | |
Output & Sorting
| Flag | Purpose | Example |
|---|---|---|
| Max results (default: 30) | |
| Sort by author-date or committer-date | |
| Sort direction: asc or desc | |
| JSON output | |
| Open in browser | |
JSON Output Fields
Available fields:
author, commit, committer, id, parents, repository, sha, url
Exclusion Syntax (Critical!)
When using inline query exclusions (negations with
-), you MUST use the -- separator:
✅ Correct:
gh search commits -- "search-terms -qualifier:value"
❌ Wrong: gh search commits "search-terms" --flag=-value
❌ Wrong: gh search commits "search-terms" --flag=!value
❌ Wrong: gh search commits --author-not=username
Examples:
(exclude author)gh search commits -- "fix -author:dependabot"
(exclude committer)gh search commits -- "merge -committer:bot"
(exclude merge commits)gh search commits -- "deploy -merge:true"
(exclude date range)gh search commits -- "refactor -author-date:<2024-01-01"
Why the
separator is required:
The --
-- tells the shell to stop parsing flags and treat everything after it as arguments. Without it, -qualifier:value inside quotes may be misinterpreted.
Critical Syntax Rules
When to Use Flag Syntax vs Query Syntax
Decision Tree:
Does your search include: - Any exclusions (NOT, minus, without, except)? → Use Query Syntax with `--` - Complex boolean logic (OR, AND)? → Use Query Syntax with `--` Otherwise: - Simple positive filters only? → Use Flag Syntax
Flag Syntax (for positive filters):
gh search commits "bug fix" --author octocat --repo cli/cli
Query Syntax with
(required for exclusions):--
gh search commits -- "deploy -author:dependabot -author:renovate"
⚠️ NEVER mix both syntaxes in a single command!
1. Exclusions and Negations
CRITICAL: When excluding results, you MUST use query syntax with the
-- separator.
Exclusion Syntax Rules:
- Use the
separator before your query-- - Use
format (dash prefix for negation)-qualifier:value - Quote the entire query string
Examples:
Single exclusion:
# Exclude specific author gh search commits -- "deploy -author:dependabot" # Exclude specific committer gh search commits -- "merge -committer:bot" # Exclude merge commits gh search commits -- "fix -merge:true"
Multiple exclusions:
# Exclude multiple authors gh search commits -- "deployment -author:dependabot -author:renovate" # Exclude author and date range gh search commits -- "refactor -author:bot -author-date:<2024-01-01" # Exclude merge commits and specific authors gh search commits -- "feature -merge:true -author:bot"
Combine with positive filters using flags:
# Wrong - mixing syntaxes: gh search commits "fix" --author octocat -committer:bot # ❌ # Correct - use query syntax for everything when excluding: gh search commits -- "fix author:octocat -committer:bot" # ✅
PowerShell exclusions:
# Use --% to prevent PowerShell parsing gh --% search commits -- "fix -author:dependabot"
Common Exclusion Patterns:
| User Request | Command |
|---|---|
| "Find commits but not by bots" | |
| "Commits excluding merge commits" | |
| "Commits not by specific author" | |
| "Commits excluding specific date range" | |
| "Commits not by multiple committers" | |
| "Commits excluding specific email" | |
| "Commits not in specific repo" | |
2. Date Formats
Use ISO8601 format (YYYY-MM-DD) with comparison operators:
gh search commits --author-date ">2024-01-01" gh search commits --committer-date "2024-01-01..2024-12-31"
3. Quoting Rules
Multi-word search:
gh search commits "bug fix"
Date comparisons need quotes:
gh search commits "refactor" --author-date "<2024-06-01"
Common Use Cases
Find commits by author:
gh search commits --author octocat --repo cli/cli
Search commit messages:
gh search commits "security fix" --repo myorg/myrepo
Find commits in date range:
gh search commits "refactor" --author-date "2024-01-01..2024-12-31"
Find merge commits:
gh search commits --merge --repo owner/repo
Exclude bot commits:
gh search commits -- "deployment -author:dependabot"
Search by commit hash:
gh search commits --hash 8dd03144
Find commits by email:
gh search commits --author-email user@example.com
Common Mistakes
| Mistake | Problem | Fix |
|---|---|---|
or | Flag syntax doesn't support negation | Use query: or |
| interpreted as flag | Use : |
| keyword doesn't work | Use : |
Mixing syntaxes: | Can't mix flags with query qualifiers | Use query for all: |
without comparison | May not work as expected | Use: |
| Not quoting date comparisons | Shell interprets operators | Quote: |
| Invalid prefix | Drop : |
PowerShell without | Breaks with exclusions | Add: |
Installation Check
If
gh command not found:
# Check if gh is installed which gh # Install: https://cli.github.com/manual/installation
If not authenticated:
# Authenticate with GitHub gh auth login
Date Comparison Operators
- After date>
- On or after date>=
- Before date<
- On or before date<=
- Date range:..2024-01-01..2024-12-31
Related
- GitHub search syntax: https://docs.github.com/search-github/searching-on-github/searching-commits
- For searching other resources:
,gh-search-code
,gh-search-issues
,gh-search-prsgh-search-repos