Git Revert and Reset
Undoing changes in Git
Revert Commit
git revert # create new commit that undoes changes
git revert HEAD # revert last commit
git revert --no-commit # revert without committing
Reset (Soft)
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset --soft # reset to specific commit
Reset (Mixed)
git reset HEAD~1 # undo commit, unstage changes
git reset # unstage all files
git reset filename # unstage specific file
Reset (Hard)
git reset --hard HEAD~1 # delete commit and changes
git reset --hard origin/main # reset to remote state
Clean Working Directory
git clean -n # dry run (show what would be removed)
git clean -f # remove untracked files
git clean -fd # remove untracked files and directories
Restore Files
git restore filename # discard changes in file
git restore --staged filename # unstage file
git restore . # discard all changes