How to discard unstaged changes in a file?
git checkout path/to/file
To discard unstaged changes in a file use git checkout path/to/file
, where path/to/file should be replaced with the path to your selected file.
git status
On branch main
Changes not staged for commit:
(use "git add..." to update what will be committed)
(use "git restore..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
git checkout README.md
Updated 1 path from the index
git status
On branch main
nothing to commit, working tree clean
See git checkout to learn more about it.