Undoing for Git and GitHubs
Undoing in Git means recovering from mistakes without losing work. Commands such as git restore, git reset, git revert and git commit --amend reverse or correct changes at different levels. Git stash shelves unfinished work temporarily, and tags mark important commits such as releases.
Stage: Git Basics · Part of the Git and GitHub roadmap · Last reviewed 19 November 2026
What to learn in Undoing
- Discard unwanted working changes with git restore
- Choose between reset soft, mixed and hard for a given situation
- Undo a pushed commit safely using git revert
- Fix the last commit message or contents with amend
- Recover lost commits using git reflog
Undoing interview questions
What is the difference between git reset and git revert?
Reset moves the branch pointer back, rewriting history, which is fine for local commits but risky for shared ones. Revert creates a new commit that undoes an earlier commit, leaving history intact, so it is the safe choice on a shared branch.
How can you recover a commit after a hard reset?
Run git reflog to see where HEAD has recently pointed, find the hash of the lost commit, then use git checkout or git branch with that hash to restore it. Reflog entries are kept for a limited time.
Where Undoing fits in the Git and GitHub roadmap
Undoing belongs to the Git Basics stage (beginner level), which takes about 9 hours. Save and inspect history.
Other units in this stage
Back to the full Git and GitHub roadmap