Git Revert Commit Safely
Create a new commit that undoes changes from a previous commit without rewriting history.
# 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.
Undo Last Git Commit (Soft and Hard)
Git commands to undo the last commit while keeping changes staged, unstaged, or fully discarded.
Git Rebase Workflow Example
Step-by-step git rebase workflow to keep feature branches up to date with main branch cleanly.
Git Cherry-Pick Commits Example
Apply specific commits from one branch to another using cherry-pick with conflict resolution.
Squash Multiple Git Commits
Interactive rebase to squash multiple commits into one clean commit before merging a feature branch.