This seems to be something I constantly have to google, so storing it here for reference.
This command updates files in the working tree to match the version in given [commitref]. It does not update HEAD
or commit/uncommit anything, so you can always go back to HEAD
with git reset --hard HEAD
.
git checkout [commitref] -- .
It’s a useful command, if you need to quickly test something in a previous commit without messing too much with the commits in between.
You can also mess with pathspec (the part after --
) to only checkout specific files. For instance, I recently used git checkout [commitref] -- '**/package.json' 'package-lock.json'
to reset npm dependencies to a known good state to debug some package resolution issues.