undo changes in git file code example Example 1: revert unstaged changes git git checkout -- . Example 2: git discard staged changes git reset HEAD git checkout .