Choose the undo by what you want to change.
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.txtUse 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_SHAWith 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~1To 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.
Which keeps existing history and adds an undo commit?
Choose an answer.
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 ·