bashbeginner
Git Revert Commit Safely
Create a new commit that undoes changes from a previous commit without rewriting history.
bashPress ⌘/Ctrl + Shift + C to copy
# Revert the most recent commit
git revert HEAD
# Revert a specific commit by hash
git revert abc1234
# Revert without auto-committing (stage changes only)
git revert --no-commit abc1234
# Revert multiple commits
git revert abc1234 def5678
# Revert a range of commits
git revert abc1234..ghi9012
# Revert a merge commit (specify parent)
# Parent 1 is main, parent 2 is the merged branch
git revert -m 1 merge-commit-hash
# If conflicts during revert:
git add .
git revert --continue
# Abort the revert
git revert --abort
# Verify the revert
git log --oneline -5
git diff HEAD~1Use Cases
- Undoing a deployed commit on shared branches
- Rolling back a feature without rewriting history
- Safely reverting merge commits in production
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashadvanced
Git Revert — Undo Merge Commits Safely
Revert merge commits safely without rewriting history, with options for parent selection.
Best for: Rolling back a broken deployment without force push
#git#revert
bashbeginner
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Best for: Fixing a commit with wrong files or message
#git#undo
bashintermediate
Git Reflog Recovery Guide
Use git reflog to recover lost commits, undo hard resets, and restore deleted branches.
Best for: Recovering from accidental git reset --hard
#git#reflog
bashbeginner
Git Reset — Soft, Mixed, and Hard Explained
Understand the three git reset modes and when to use each for undoing commits safely.
Best for: Undoing accidental commits before pushing
#git#reset