This skill should be used when the user asks to "use git blame", "check git history", "find git commits", "use git log", "use git diff", "use git bisect", "trace code changes", "find who changed this code", or mentions using git commands for investigating code history and changes during root cause analysis.
This skill inherits all available tools. When active, it can use any tool Claude has access to.
examples/bisect-script.shreferences/git-aliases.mdreferences/git-workflows.mdGit is a distributed version control system that tracks code changes over time. This skill provides guidance for using git commands to investigate code history, identify when bugs were introduced, and track down specific changes during root cause analysis.
Apply this skill when:
Basic usage:
git log
Useful flags for RCA:
Show commits with diffs:
git log -p
Show commits for specific file:
git log -- path/to/file.js
Show commits in time range:
git log --since="2025-12-19 00:00" --until="2025-12-19 23:59"
Show one-line summaries:
git log --oneline
Show commits by author:
git log --author="Developer Name"
Show commit graph:
git log --graph --oneline --all
Search commit messages:
git log --grep="database" --grep="pool" --all-match
Format output:
git log --format="%h %an %ad %s" --date=short
Basic usage:
git blame path/to/file.js
Show line ranges:
git blame -L 40,50 path/to/file.js
Show email addresses:
git blame -e path/to/file.js
Follow line history through renames:
git blame -C -C -C path/to/file.js
Show commit details:
git blame -s path/to/file.js
Blame output format:
abc123de (Developer Name 2025-12-19 10:15:00 +0000 45) max: 10,
abc123de: Commit SHADeveloper Name: Author2025-12-19 10:15:00: Timestamp45: Line numbermax: 10,: Code contentCompare working directory with last commit:
git diff
Compare specific commits:
git diff commit1 commit2
Compare file across commits:
git diff commit1 commit2 -- path/to/file.js
Compare with previous commit:
git diff HEAD~1 HEAD
Show diff for specific commit:
git show commit_sha
Unified diff with context:
git diff -U5 # Show 5 lines of context
Word-level diff:
git diff --word-diff
Show complete commit:
git show commit_sha
Show specific file in commit:
git show commit_sha:path/to/file.js
Show commit metadata only:
git show --stat commit_sha
Use when: You know code worked at one point and is broken now, but don't know which commit broke it.
Workflow:
git bisect start
git bisect bad
git bisect good commit_sha # or tag, or HEAD~20
Test current code (git checks out midpoint)
git bisect badgit bisect goodRepeat until git identifies first bad commit
End bisect:
git bisect reset
Automated bisect:
git bisect start HEAD v1.0
git bisect run ./test-script.sh
Test script should exit 0 for good, non-zero for bad.
Goal: Identify when specific line was last modified
Steps:
git blame path/to/file.js | grep "suspicious code"
Extract commit SHA from blame output
View commit details:
git show commit_sha
Goal: See all changes to a file over time
Steps:
git log -p -- path/to/file.js
git log --since="2025-12-18" --until="2025-12-19" -- path/to/file.js
Goal: Identify recent commits affecting several related files
Steps:
git log --since="2025-12-19" --stat
git log --since="2025-12-19" -- src/config/
Goal: Find commits related to specific feature or bug
Steps:
git log --grep="database" --grep="connection" --all-match
git log --grep="database\|connection\|pool"
Goal: Identify differences between deployed and current code
Steps:
deployed_sha="abc123"
git diff $deployed_sha HEAD
git diff $deployed_sha HEAD -- path/to/file.js
Goal: Find exact commit that introduced bug
Steps:
git log --oneline
# Find commit SHA before issue appeared
git bisect start
git bisect bad # Current is broken
git bisect good good_commit_sha
Test each checkout:
git bisect good or git bisect badGit identifies first bad commit
Review that commit to find root cause
Search for deleted lines:
git log -S "deleted code pattern" --all
Example - Find when "max: 100" was removed:
git log -S "max: 100" -- src/config/database.js
Track file across renames:
git log --follow -- path/to/file.js
Blame with rename detection:
git blame -C -C -C path/to/file.js
Show commits by diff size:
git log --stat --format="%h %s" | head -20
Find commits with many changes:
git log --shortstat | grep -E "file.*change"
View commit details:
git show commit_sha
View files changed in commit:
git show --name-only commit_sha
View commit as patch:
git format-patch -1 commit_sha
abc123de src/config/database.js (Developer Name 2025-12-19 10:15:00 +0000 45) max: 10,
Extract:
abc123desrc/config/database.jsDeveloper Name2025-12-19 10:15:0045max: 10,Action: Check if timestamp correlates with incident start.
commit abc123def456789
Author: Developer Name <dev@example.com>
Date: Thu Dec 19 10:15:00 2025 +0000
Refactor database configuration
Align pool size with staging environment
Extract:
abc123def456789Developer Name <dev@example.com>Thu Dec 19 10:15:00 2025Red flags:
diff --git a/src/config/database.js b/src/config/database.js
index abc123d..def456e 100644
--- a/src/config/database.js
+++ b/src/config/database.js
@@ -42,7 +42,7 @@ function createConnectionPool() {
return new Pool({
host: process.env.DB_HOST,
port: process.env.DB_PORT,
- max: 100,
+ max: 10, // Align with staging
min: 10,
idleTimeoutMillis: 30000
});
Interpret:
- line: Old code (removed)+ line: New code (added)@@ -42,7 +42,7 @@: Line numbers (start at line 42, 7 lines shown)Identify issue: max: 100 → max: 10 is likely problematic reduction.
git log --since="2025-12-19 00:00" --until="2025-12-19 23:59"
git log -- src/config/
git log --author="Developer" --since="1 week ago" -- src/
git log --grep="database"
git log --follow -- file.js
git bisect start HEAD v1.0.0
git log without filters (too much output)This skill integrates with:
Agent can execute git commands:
# Find recent commits to file
git log --since="24 hours ago" --oneline -- src/config/database.js
# Blame specific line
git blame -L 45,45 src/config/database.js
# Show commit details
git show abc123
# Compare versions
git diff HEAD~1 HEAD -- src/config/database.js
Agent parses output to extract commit SHAs, authors, timestamps, and changes.
git blame on that file/linegit show to review commitgit log --since="1 week ago" -- config/ src/config/
git show commit_sha
git diff previous_commit deployed_commit
git bisect start HEAD good_commit
git bisect run ./test-reproduction.sh
For advanced git techniques:
references/git-aliases.md - Useful git aliases for RCAreferences/git-workflows.md - Complete RCA investigation workflowsWorking examples:
examples/bisect-script.sh - Sample automated bisect scriptRecent commits: git log --since="1 day ago" --oneline
Blame line: git blame -L 45,45 file.js
Show commit: git show abc123
Diff commits: git diff commit1 commit2
Search messages: git log --grep="pattern"
File history: git log -p -- file.js
Binary search: git bisect start HEAD good_commit
Correlate timestamps: Always compare git timestamps with incident timeline
Follow renames: Use --follow flag for moved files
Read full diffs: Don't just trust commit messages
Master git investigation techniques to efficiently trace code history and identify exact commits that introduced production issues.