git revert a file 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: how to undo a modified file in git

# If you want to revert the changes only in current working directory
git checkout -- .

# discard anything (note: you have to be in the directory
# where all of the changes are located)
# or you can use the command on line 9, you can discard anything
# on the repo
git checkout -- *
git checkout -- :/

# or if you check the git status message after modifying a file 
# there is this command 
git restore <file>

Example 3: git revert one file

git checkout HEAD -- /directory/my-file.txt

Example 4: how to remove file changes in git

git clean -df
git checkout -- .

Example 5: git reset one file

git checkout HEAD -- my-file.txt

Example 6: reset certain file git

git checkout c5f567 -- file1/to/restore file2/to/restore