# Go back 1 commitwit reset HEAD~1wit reset HEAD^# Go back 3 commitswit reset HEAD~3wit reset HEAD^^^# Reset to specific commitwit reset abc1234# Reset to branchwit reset origin/main
# Undo last commit but keep changes staged (ready to recommit)wit reset --soft HEAD~1# ✓ Reset soft to abc1234# Was: def5678# Your changes are still staged.# Undo last commit, unstage changes (for editing before recommit)wit reset HEAD~1# ✓ Reset mixed to abc1234# Was: def5678# Your changes are preserved but unstaged.# Completely discard last 3 commitswit reset --hard HEAD~3# ✓ Reset hard to abc1234# Was: def5678# Working directory has been reset.# Unstage a filewit reset src/file.ts# Unstaged: src/file.ts
Danger Zone: wit reset --hard discards changes permanently. Always double-check before using it. Consider wit snapshot first.
# If cherry-pick causes conflicts:wit cherry-pick abc1234# error: Cherry-pick stopped due to conflicts in 1 file(s)# Resolve conflicts# Edit the conflicted fileswit add resolved-file.tswit cherry-pick --continue# Or skip this commitwit cherry-pick --skip# Or abort entirelywit cherry-pick --abort
# On main branch, get the fix commit hashwit log --oneline# abc1234 Fix security vulnerability# Switch to release branchwit switch release-1.0# Apply the fixwit cherry-pick abc1234
Extract commits from a branch
Copy
# Pick specific commits from feature branch to mainwit switch mainwit cherry-pick feature~3 # Third commit from tipwit cherry-pick feature~2 # Second commit from tip
Reapply commits on top of another base commit. This creates a linear history.
Copy
# Rebase current branch onto mainwit rebase main# Rebase onto a specific commitwit rebase <commit># Interactive rebase (coming soon)wit rebase -i HEAD~3# Continue after resolving conflictswit rebase --continue# Abort rebasewit rebase --abort# Skip current commitwit rebase --skip
# Update feature branch with latest mainwit switch featurewit rebase main# Output:# Rebasing feature onto main...# ✓ Successfully rebased 3 commits# If conflicts occur:# Resolve conflicts in the filewit add resolved-file.tswit rebase --continue
Never rebase shared branches: Rebasing rewrites commit history. If others have based work on your commits, rebasing will cause problems. Only rebase local, unpushed commits.