-1

i'm working on a project on VSCode. I made lot of changes to a file, then I accidentaly deleted it without pushing it to the repo. Then, for recovering it, I went to source control->discard changes to the file. However, the file has been restored with the last commit, therefore I lost all my changes. How can I recover the original file? Note than I didn't even commited it to the local repo.

Thank you very much

I tried to do git checkout but did not work.

Wassim
  • 1
  • 1
    If you haven't stashed, committed, or pushed the file in the form you're looking for, it's unavailable from git. Maybe you can find it in your OS's "trash"/"recycle bin". – Paul Dempsey May 10 '23 at 19:57

2 Answers2

0

Git doesn't have an "auto-save"/"auto-commit" behavior. If you haven't added files to git via committing or stashing or staging ("pushing" is same as "committing", just to a remote repo instead of local repo), then git doesn't know about it, and can't be used as a backup.

You wouldn't be the first person to consider setting up git to auto-commit, though:

Making git auto-commit

Kache
  • 15,647
  • 12
  • 51
  • 79
0

In this situation, you can not restore the code that was lost. Git manage code by operating git add and git commit. Another way, you can use git stash to save the changes (to discard the changes), and then working storage will return last commit (nothing add).

Only when you want to delete code that you definitely no longer needed, you can try git restore file name or git checkout file name

Manh Do
  • 111
  • 8