Sequence NODE_346
Medium

Undo a Commit Safely (Without Losing Work)

Git & GitHub
Technical Specification

Practice undoing last commit using git reset --soft, and git revert for already pushed commits.

Input/Output Samples
Input:bad commit pushed
Output:use git revert <hash>
Optimal Logic Path
# undo last local commit, keep changes staged
git reset --soft HEAD~1

# revert a specific commit safely
git revert <bad-commit-hash>
Architectural Deep-Dive
Choosing correct undo method depends on whether commit is already shared with others or not.