MEPX
Chapter 10 of 14All chapters

Chapter 10 of 14

Undoing work

Three commands with very different reach.

Restore, reset, revert

git restore throws away changes in a file. git reset moves the branch label, and with --hard it discards local changes for good. git revert undoes a commit by adding a new one.

  • On a shared branch, revert is the only safe option of the three.
  • Changes that were never committed cannot be recovered.

The reflog

git reflog records where your branch pointed recently, even after a reset. It is the closest thing Git has to an undo history for the commands themselves.