chevron_left
Cookbooks
Amending the most recent commit messageChecking git versionCreating a new repositoryDiscarding unstaged changesExiting git log or git diffGetting help on Git commandsGetting the current branch namePagination for output of git commandsRemoving local untracked filesReverting a file to a specific revisionUndoing staged changesUndoing staged changes before commitViewing commit history
0
0
0
new
Discarding unstaged changes in Git
Software Development
chevron_rightGit
chevron_rightCookbooks
schedule Mar 10, 2022
Last updated tocTable of Contents
expand_more To discard unstaged changes in Git you can use the git checkout
command. This is useful when you have made changes to a file that have not yet been staged and you would like to undo them.
Examples
To discard all unstaged changes in the current working directory:
git checkout -- .
To discard all unstaged changes for a particular file:
git checkout -- <filepath>
where <filepath>
refers to the filepath of the file you would like to remove all unstaged changes for.
WARNING
Be careful when using this command as once changes are discarded they cannot be recovered.
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...