How do I discard unstaged changes in Git

For a specific file use:

git checkout path/to/file/to/revert

For all unstaged files use:

git checkout -- .

Make sure to include the period at the end

 

Another quicker way is:

git stash save --keep-index

After that, you can drop that stash with a git stash drop command if you like.

git clean -df

Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

-d: Remove untracked directories in addition to untracked files

-f: Force (might be not necessary depending on clean.requireForce setting)

Run git help clean to see the manual

Leave a Reply

Your email address will not be published. Required fields are marked *