0

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

git checkout -- folder/*

2
  • Unfortunately, all the changes that weren't committed or staged are not stored in git. Hopefully your IDE keeps a track of the successive states of your files when you hit Ctrl+S, or you can turn to a file recovery tool for your OS.
    – LeGEC
    Commented Sep 21, 2022 at 4:48
  • If your code was staged (as in git add folder/myfile or git add folder) at some point, and your actual sequence of commands was git reset HEAD; git checkout -- folder/*, you may look at this answer
    – LeGEC
    Commented Sep 21, 2022 at 4:50

1 Answer 1

2

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.