Git Stash
Stash temporarily saves your uncommitted changes so you can switch branches or pull updates without committing work in progress.
Example
# Stash current changes
git stash
# Stash with a message
git stash push -m "WIP: login form"
# List stashes
git stash list
# Apply most recent stash (keep in stash list)
git stash apply
# Apply and remove from stash list
git stash pop
# Apply a specific stash
git stash apply stash@{2}
# Drop a stash
git stash drop stash@{0}
# Clear all stashes
git stash clear Git Reset
Reset moves your branch pointer and can modify the staging area and working directory. Use with caution.
Example
# Soft reset — undo commit, keep changes staged
git reset --soft HEAD~1
# Mixed reset (default) — undo commit, unstage changes
git reset HEAD~1
# Hard reset — undo commit AND discard changes
# WARNING: This permanently deletes uncommitted work
git reset --hard HEAD~1
# Reset a specific file from staging
git restore --staged filename.js
# Discard changes in working directory
git restore filename.js Git Revert
Unlike reset, revert creates a new commit that undoes changes. This is safe for shared branches.
Example
# Revert a specific commit (creates a new undo commit)
git revert abc1234
# Revert without auto-committing
git revert --no-commit abc1234
# When to use revert vs reset:
# revert — safe for shared branches (main, develop)
# reset — OK for local branches not yet pushed 