git reset of a single file

Snippet

git reset will discard any local changes you have in the current branch you have checked out.

Sometimes, however, you want to reset a single file, not the whole branch. In this case, use checkout, but use the special "option" --, which is unix for "treat every argument after this point as a file name, no matter what it looks like."

# general case
git checkout HEAD -- [file]
 
# my specific case used ALL THE TIME
git checkout HEAD -- package-lock.json

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.