Zest.

Git: Discard changes to a file

A short, tested Git example for discard changes to a file. Copy it and adjust the names and paths for your project.

Git
git restore file.txt              # discard unstaged changes
git restore --staged file.txt     # unstage
git restore --source=HEAD~2 file.txt   # file as it was two commits ago
git clean -fd                     # remove untracked files (destructive)

Find it in Zest

Search for “git discard changes to a file” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Git examples

All Git examples