Skip to content

Git Undo Commands

Posted by author

To undo changes in Git, you can use the following commands, depending on what you want to undo:

  1. Undo uncommitted changes in the working directory:

    1git checkout -- <file>
  2. Unstage a staged file:

    1git reset <file>
  3. Undo the last commit but keep changes:

    1git reset --soft HEAD~1
  4. Undo the last commit and discard changes:

    1git reset --hard HEAD~1

Choose the command based on your requirement. Always be cautious with --hard as it irreversibly deletes changes.


Syntax highlighting by Torchlight.dev

End of article