skills/coding/git-history-rewrite/SKILL.md
Master git history manipulation: when modifying history is safe, git reset/rebase alternatives, and maintaining history integrity. Use when user mentions git history, rewriting commits, git reset, amending commits, or when they want to clean up commit history. Triggers especially when user says "clean up history", "rewrite git history", "git reset", "amend commit", or "squash commits".
npx skillsauth add ImaginerLabs/skill-manager git-history-rewriteInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Git-history-rewrite is a behavioral specification skill that encapsulates the judgment of when modifying history is safe, which tool to use, and how to avoid breaking things.
This skill embodies the experience of developers who've learned (sometimes painfully) that rewriting history is powerful but dangerous, and the key is knowing when it's appropriate.
Rule 1: Never rewrite public/shared history Rule 2: If you broke Rule 1, communicate immediately
┌─────────────────────────────────────────────────────────────┐
│ HISTORY REWRITE SAFETY │
│ │
│ SAFE: Local-only branches that haven't been shared │
│ ✓ Your feature branch │
│ ✓ Commits you haven't pushed │
│ ✓ Branches that only you have │
│ │
│ DANGEROUS: Shared or published branches │
│ ✗ Main/develop branches │
│ ✗ Pushed feature branches │
│ ✗ Branches others have checked out │
│ ✗ Any branch in a PR │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ TOOL SELECTION │
│ │
│ Want to... Use... Safe if... │
│ ───────── ───── ────────── │
│ Fix last commit message git commit --amend Not pushed │
│ Add file to last commit git commit --amend Not pushed │
│ Remove last commit git reset Not pushed │
│ Combine multiple commits git rebase -i Local only │
│ Remove commits entirely git rebase -i Local only │
│ Move branch to new base git rebase Local only │
│ Undo pushed changes git revert Always safe │
└─────────────────────────────────────────────────────────────┘
| Tool | Use When | Don't Use When |
|------|----------|----------------|
| commit --amend | Fix last commit message/add forgotten file | Pushed commits |
| git reset | Undo uncommitted changes, clean staging | Pushed commits |
| git rebase -i | Squash/fixup/reorder commits before PR | Pushed/shared branches |
| git revert | Undo published changes safely | Simple local cleanup |
| git filter-branch | Mass history changes | Almost never needed |
# SOFT: Move branch pointer, keep changes staged
git reset --soft HEAD~1
# Result: Last commit unstaged, changes ready to recommit
# MIXED (default): Move branch pointer, unstaged
git reset HEAD~1
# Result: Last commit unstaged and unstaged
# HARD: Move branch pointer, DISCARD changes
git reset --hard HEAD~1
# WARNING: This deletes work!
┌─ Did you push this commit?
│ └─ YES → DON'T RESET
│ └─ Use git revert instead
│ └─ NO → Continue
│
└─ Do you want to keep the changes?
└─ NO → git reset --hard (DANGEROUS!)
└─ YES → Continue
│
└─ Do you want to recommit?
└─ YES → git reset --soft
└─ NO → git reset --mixed
# Clean up last N commits
git rebase -i HEAD~5
# Commands available in interactive mode:
pick abc1234 Add user authentication # Use commit as-is
fixup def5678 Fix typo # Squash into previous, discard message
squash ghi9012 WIP # Squash into previous, keep messages
reword jkl2345 Update readme # Change commit message
drop mnop6789 WIP debugging # Remove commit entirely
exec uvwx9012 npm test # Run command during rebase
# Scenario 1: Squash commits into one
pick abc123 Add feature
fixup def567 Fix typo
fixup ghi890 Fix another typo
# Result: One commit with all changes
# Scenario 2: Reorder commits
pick abc123 Add feature A
pick def456 Add feature B
# Can reorder to change order
# Scenario 3: Edit commit message
pick abc123 Update readme
reword abc123 Add better readme
# Opens editor to change message
# Scenario 4: Split a commit (advanced)
# In rebase, mark commit as "edit"
# Then git reset HEAD~
# Then git add + git commit multiple times
# Then git rebase --continue
## Pre-Cleanup Safety Check
□ Is this branch local only?
□ Has it been pushed to remote?
□ Have others branched from this?
□ Is there a PR open?
If ALL NO → Safe to rewrite
If ANY YES → DO NOT rewrite, consider alternatives
# 1. Fix the last commit message
git commit --amend -m "fix(auth): correct typo in login validation"
# 2. Add forgotten file to last commit
git add forgotten-file.ts
git commit --amend --no-edit
# 3. Combine commits on a feature branch
git rebase -i HEAD~3
# Change 'pick' to 'fixup' for commits to combine
# 4. Remove a commit entirely (local only!)
git rebase -i HEAD~5
# Change 'pick' to 'drop' for commit to remove
# REFLOG is your safety net
git reflog
# Shows all places HEAD has been
# Format: HEAD@{N} - description
# Recover a "lost" commit
git checkout abc1234 # The commit hash from reflog
# Creates detached HEAD, can branch from here
git branch recovered-work
# Or reset back to a reflog point
git reset --hard HEAD@{5}
## INCIDENT: Pushed History Rewritten
IMMEDIATE ACTIONS:
1. STOP - Don't push more changes
2. ASSESS - Who might have this history?
3. COMMUNICATE - Tell affected team members
4. RECOVER - Help them get back to correct state
PREVENTION:
1. Always check if branch is shared before rewriting
2. Use --force-with-lease instead of --force
3. Prefer merge over rebase for shared branches
# BEFORE PR, clean up commits
git rebase -i HEAD~5
# Typical cleanup in editor:
pick abc123 Add feature
fixup def456 Fix typo in comment
fixup ghi789 Fix typo in function name
drop jkl012 WIP debugging
drop mnop345 More debugging
# Result: Clean history with 2-3 meaningful commits
# Oops! Committed to main instead of feature branch
# Solution 1: Move to feature branch
git branch feature-temp # Create branch from current main
git reset --hard origin/main # Reset main back
git checkout feature-branch # Switch to feature
git merge feature-temp # Merge the work
git branch -d feature-temp # Clean up
# Solution 2: If you haven't pushed
git reset --soft HEAD~1 # Uncommit but keep staged
git stash # Stash the changes
git checkout feature-branch # Switch to feature
git stash pop # Get changes back
# DON'T: git reset (rewrites history)
# DON'T: git rebase (rewrites history)
# DO: Use git revert (safe, creates new commit)
git revert HEAD
# This creates a NEW commit that undoes the change
# Pushes the "undo" to shared history
# Everyone can pull safely
HISTORY REWRITE DECISION CHECKLIST
===================================
□ 1. Is this history local only?
└─ YES → Rewrite may be safe
└─ NO → STOP, don't rewrite
□ 2. Has this been pushed?
└─ YES → Use git revert instead
└─ NO → Continue
□ 3. Is this a PR branch?
└─ YES → Coordinate with reviewers
└─ NO → Continue
□ 4. Do others have this branch checked out?
└─ YES → Coordinate with them first
└─ NO → Continue
□ 5. Have you created a backup?
└─ YES → Good!
└─ NO → git branch backup/branch-name
□ 6. Do you understand the tool you're using?
□ git reset --hard = PERMANENT deletion
□ git rebase -i = Interactive review
□ git revert = Safe undo
TOOL SELECTION:
□ commit --amend → Last commit, message/content fix
□ git reset → Undo commits, keep/don't keep changes
□ git rebase -i → Multiple commits, reorder/fix/squash
□ git revert → Undo published changes safely
# DANGEROUS!
git push --force
# If others have this history, you just broke their branches
# Their commits now point to commits that don't exist
# SAFER: --force-with-lease
git push --force-with-lease
# Refuses if remote has commits you don't have
# Still dangerous but slightly safer
# BAD: No backup before risky operation
git reset --hard HEAD~5
# 5 commits deleted...
# GOOD: Create backup first
git branch backup-before-cleanup
git reset --hard HEAD~5
# If something goes wrong, backup exists
# OVERKILL for most cases
git filter-branch --tree-filter 'rm -f password.txt'
# CONSIDER: git-filter-repo (newer, faster)
# Or: Ask if you really need this
# 1. Fetch latest
git fetch origin
# 2. Rebase onto latest main
git rebase -i origin/main
# OR: git merge origin/main if rebasing is complex
# 3. Clean up during rebase
# pick → use
# fixup → combine, discard message
# squash → combine, keep messages
# drop → remove
# 4. Push (may need --force-with-lease)
git push --force-with-lease origin feature-branch
# 1. If last commit not pushed
git commit --amend
# 2. If commit from a few ago, not pushed
git rebase -i HEAD~3
# Mark as 'reword' for message or 'fixup' for content
# 3. If pushed commit needs undoing
git revert HEAD
git push
# 1. Check reflog
git reflog
# 2. Find the good state
git reflog | grep "your-branch"
# abc1234 your-branch: commit: Feature X
# def5678 your-branch: reset: to "origin/..."
# 3. Recover
git reset --hard abc1234
If others have it, don't rewrite it. Use revert instead.
You own your local branches. Clean up before sharing.
Create a branch or tag before reset --hard or complex rebase.
Until pushed, commit messages are editable. Do it before sharing.
Even after a mistake, reflog can usually recover your work.
# View reflog
git reflog
# Output example:
# abc1234 HEAD@{0}: reset: moving to HEAD~2
# def5678 HEAD@{1}: commit: WIP feature
# ghi9012 HEAD@{2}: commit: More WIP
# jkl3456 HEAD@{3}: checkout: moving to feature
# Recover to specific point
git checkout HEAD@{1}
# Or reset
git reset --hard HEAD@{1}
git-branch-strategy — Branch decisions affect historygit-rebase-safety — Rebase is a form of history rewritegit-merge-resolution — Alternative to rewritinggit-commit — Amending improves commit messagesgit-stash-management — Stashing before risky operationsdevelopment
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.
devops
Create a new implementation plan file for new features, refactoring existing code or upgrading packages, design, architecture or infrastructure.
tools
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
documentation
Generates standardized porting documentation from completed feature changes. Analyzes commit diffs or file contents, extracts change intent, and outputs Markdown documentation for cross-team understanding. Should be used when the user needs to document a change for cross-team or cross-project consumption. Distinguished from cross-branch-fix-porter which actively re-implements fixes, this skill documents changes.