undo changes in git

Throw away changes not committed yet, unstage files, or put work aside for later.

  • version-control

danger Steps marked in red delete, overwrite or stop something. Read each one before you run it.

Steps

  1. git status

    what changed, staged or not

  2. git restore file.txt

    danger throw away one file's changes

  3. git restore --staged file.txt

    danger unstage it, keeping the changes

  4. git stash

    put every change aside; git stash pop brings them back

  5. git clean -nd

    list the new files git does not track

  6. git clean -fd

    danger delete them

  7. git reset --hard

    danger throw away every change to tracked files

Notes

  • restore, clean -fd and reset --hard cannot be undone for changes never committed.

Commands used

  • git

Each has a page in lore: lore git opens it.