The Essential Git Rebase & Conflict Resolution Cheat Sheet
Quick reference for interactive rebasing (git rebase -i), squash/fixup workflows, resolving conflict markers, and emergency reflog recovery.
Table of Contents
Interactive Rebase Commands (git rebase -i)
Sub-commands used inside the interactive rebase TODO buffer.
| Command | Short Key | Action Description |
|---|---|---|
| `pick` | `p` | Keep the commit as-is and re-apply it onto the new base. |
| `squash` | `s` | Meld the commit into the previous commit and edit combined commit message. |
| `fixup` | `f` | Meld commit into previous commit, discarding this commit's message log. |
| `reword` | `r` | Keep the commit's code changes but pause to edit the commit message. |
| `drop` | `d` | Completely remove the commit and discard all its code changes. |
Resolving Conflicts & Emergency Recovery
Terminal commands to resolve conflicts or undo botched rebases.
# Start rebase onto updated main branch
git checkout feature-branch
git rebase main
# If conflict occurs, inspect conflicted files
git status
# After manually editing conflict markers, stage resolved files
git add path/to/resolved-file.ts
# Continue the rebase
git rebase --continue
# Emergency: completely abort and return to exact prior state
git rebase --abort
# Recovery: find lost commits using the reference log
git reflog
git reset --hard HEAD@{2}Interactive Client-Side Tools for this Guide
Test and run these patterns directly inside your browser with zero server uploads:
Interactive Git Command Generator & Undo Cheatsheet
Never panic about broken Git history again. Generate precise commands for undoing commits, squashing changes, stashing work, and branch renaming.
Text Diff Checker (Compare Text Differences)
Find exact changes between original and revised drafts of essays, contracts, articles, or source code.
Frequently Asked Questions
What is the Golden Rule of Git Rebasing?
Never rebase a branch that has been pushed to a shared public repository (like main or staging) that other developers are actively branching from.
Can git reflog recover commits deleted by git reset --hard?
Yes! Git retains unreachable commits in the reflog for typically 30 to 90 days before garbage collection runs.