0

I have discarded 1.5k changes by mistake, it's literally 20 days of work, my last safe version it's 20days ago, pls guys is there's any way so I can get my changes back?

rioV8
  • 24,506
  • 3
  • 32
  • 49
Oxy Gène
  • 31
  • 6
  • 1
    "it's literally 20 days of work"—did you really go nearly three weeks without making a commit? I encourage my team to commit multiple times per day. – ChrisGPT was on strike Apr 27 '22 at 19:11
  • In any case, what version of Visual Studio Code are you using? The latest release [includes a local history feature that _might_ be able to help](https://code.visualstudio.com/updates/v1_66#_local-history). – ChrisGPT was on strike Apr 27 '22 at 19:12
  • did you change 1500+ files in 20 days, that is a lot of work, and a big project – rioV8 Apr 27 '22 at 20:17
  • I was working alone I know I'm stupid because I didn't expected that (I don't have local history in vsc). – Oxy Gène Apr 27 '22 at 20:21
  • YEAAAH +1.5k changes, I'm really about to cry because it's my final project for studying and I really put so much energy and time in it, I'll just take a day break and go back to it stronger. – Oxy Gène Apr 27 '22 at 20:26
  • Did you run `git add` or `git stash` on these files if not `git commit`? – ElpieKay Apr 28 '22 at 03:10

1 Answers1

1

Update:

VSCode just added this as a new feature: https://github.com/microsoft/vscode/issues/26339

Original Answer:

I'm afraid your work is most likely lost. However, if you're lucky, you might be able to undo (Ctrl+Z) in the editor.

To see a history of Git commands VSCode has executed, you can open the output console following these instructions.

From the answer here:

The Clean All (discard all changes) option in VS code essentially executes:

git clean -fd
git checkout -- .

So it is git's hands whether git clean -fd can undo discarding uncommitted changes. Unfortunately the changes are not stored in git since it not committed, so after git clean -fd is executed, git will remove untracked files by force.

After executing the command git checkout -- ., git will checkout all the modified files in git as the version of last commit.

Consider it a lesson learned - remember to commit often. This is exactly why we have version control. If you don't want to pollute your git history, you can create WIP commits, then rebase to clean up the history before you push to a remote. Alternatively for VSCode, I like to use an extension called Checkpoints, which allows you to create checkpoints between commits for a local short-term history of work.

ExplosiveFridge
  • 190
  • 1
  • 6
  • My last commit was 20 days ago so that won't help, and I gave up on it now I'm starting my project again, and have a nice day man <3 – Oxy Gène Apr 30 '22 at 10:04