Discard uncommitted or untracked changes in Git
Made some changes you don't want to keep? Nothing to worry about, you can simply discard them and move on.
Discard uncommitted changes
If you have made changes to your files but haven't committed them yet, you can discard them using the git reset --hard HEAD
command. This command will reset your working directory to match the latest commit on the current branch, discarding all uncommitted changes.
# Usage: git reset --hard HEAD git reset --hard HEAD # Discards all uncommitted changes
Discard untracked changes
Similarly, if you have untracked files in your working directory that you want to discard, you can use the git clean -f -d
command. This command will remove all untracked files and directories from your working directory.
# Usage: git clean -f -d git clean -f -d # Discards all untracked changes