What is the difference between git reset, git revert and git restore?
Quick Answer
git revert <sha> creates a new commit that undoes an earlier one — safe for shared history. git reset moves the branch pointer back (and optionally the index/working dir with --soft/--mixed/--hard) — rewrites history, only for local commits. git restore discards changes in files (working dir or index) without touching commits.
git revert makes a brand-new commit that's the inverse of a previous one, so it's what I use to undo something that's already on the shared branch — it doesn't rewrite anyone's history. git reset moves my branch pointer backwards; with --soft it keeps my changes staged, --mixed unstages them, --hard throws them away entirely, and because it rewrites history I only use it on local unpushed commits. git restore is the newer command for file-level operations — unstaging a file or discarding uncommitted edits — without touching commits at all.
reset --soft— move HEAD, keep everything staged (redo the commit).--mixed(default) — unstage too.--hard— also discard working changes (dangerous).revertis the right tool to undo something already pushed — it doesn't rewrite what others have.restore --staged fileunstages;restore filethrows away working edits;restore --source=<sha> filerestores an old version.reset --hardloss is often recoverable viagit reflogif you act quickly.