Reset vs revert vs restore
Choose the undo by what you want to change.
Restore changes files
Use restore for working-tree or staging changes, not to remove a commit from branch history. By default it restores a working file from the index. --staged restores the index from HEAD unless you specify another source.
git restore --staged notes.txt
git restore notes.txtRevert records a new undo commit
Use revert for a committed change you want to undo without rewriting the existing shared history. It can conflict, and a merge commit requires a deliberate mainline choice.
git revert COMMIT_SHAReset moves the branch
With a commit argument, reset moves the current branch. --soft keeps index and working files; --mixed resets the index and keeps working files; --hard resets both and can discard work. Do not use hard reset as a routine cleanup.
git reset --soft HEAD~1A decision before a command
To unstage a file, use restore --staged. To undo an already shared ordinary commit, usually revert it. To rework an unshared latest commit while keeping its changes staged, soft reset can fit. These are different goals, not interchangeable spellings.
Quick check
Which keeps existing history and adds an undo commit?
Choose an answer.
Sources and scope
Command blocks are syntax examples checked against official documentation, not fabricated terminal output. Replace uppercase placeholders with your actual names and inspect status before commands that change work.
git-reset · git-revert · git-restore ·