discard changes in git command code example

Example 1: git discard local changes

# Discarding local changes (permanently) to a file:
git checkout -- <file>

# Discard all local changes to all files permanently:
git reset --hard

Example 2: git undo all changes

git reset --hard

Example 3: how to remove file changes in git

git clean -df
git checkout -- .

Example 4: undo unstaged changes git

git checkout -- .

Example 5: git reset one file

git checkout HEAD -- my-file.txt

Example 6: git discard staged changes

git reset HEAD
git checkout .