git revert changes 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: undo git
# KEEP CHANGES
git reset --soft HEAD~1
# REMOVE CHANGES
git reset --hard HEAD~1
Example 3: revert git commit
git revert <the_commit_hash>
Example 4: git undo all changes
git reset --hard
Example 5: undo unstaged changes git
git checkout -- .
Example 6: git reset one file
git checkout HEAD -- my-file.txt