How to discard unstaged changes in Git?

You can use git checkout — command to discard tracked changes and git clean -fd command to discard untracked changes.

Example:

Create a new git local repository:

Create first commit:

Check git status:

Do some changes in your working tree:

Check git status:

Discard working tree tracked changes (file1):

Check git status:

Discard working tree untracked changes (file2):

Check git status:

Remove your git local repository:

Leave a Reply