git > restore with git checkout

Pavol Kutaj
1 min readAug 4, 2020

--

scenario: working on something and you just don’t want to create .old, i.e. you just want to be able to go to the last commit of that file

CHECKOUT ➔ git checkout: undo local uncommitted file changes

Note: Dangerous!

git add foo.bar && git commit -m foo-bar -RESTORE point
  • this file in that state is committed and is waiting to be pushed
  • start working and experimenting
  • discarding local changes (permanently) to a file: git checkout --<file>
git checkout -- 2020-07-17.js
  • the file will be OVERWRITTEN
  • if I want to return to a particular version of the commit I combine the SHA with the filename
git checkout 55fc911 "2020-05-18.js"

I’ve always been uncomfortable with this GIT CHECKOUT command because it’s used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).

- https://stackoverflow.com/a/215731

From https://github.com/pkutaj/kb/blob/master/git/2020-07-19-GIT-undo.md

--

--

No responses yet