Abandon changes to the workspace (not submitted to the staging area):
# Abandon the modification of the specified file git checkout -- file git restore <file> # Abandon all file modifications git checkout -- . git restore .
Abandon modifications that have been added to the staging area:
# Abandon the modification of the specified file git reset HEAD <file> git restore --staged <file> # Abandon all file modifications git reset HEAD . git restore --staged .
git restore is a command after version 2.23. If you are prompted that the command cannot be found, please update the git to the latest version.
Abandon the submitted modification (not pushed to the remote warehouse), Please refer to Section WithdrawCommit of Chapter BasicKnowledge.