Revert (use "git checkout -- <file>..." to discard changes in working directory)

Viewed 28

I accidentally ran this command and lost my code. Is it revertable?

git checkout -- folder/*

1 Answers

Since it is not revertible, check your IDE in which you developed that code.

If you have a recent enough VSCode, you should be able to:

  • recreate the file (empty)
  • check the timeline view which provides a local history of said file, allowing you to restore a past content (even when not saved in a Git commit)

That supposes however that you remember how those files were named.

The other option is to check if you had activated Time Machine on your Mac.

In the future, use git switch instead of git checkout: it deals only with branches, and will not override files.

Related