1

I accidentally discarded saved changes to file which is neither committed nor staged. What can i do to recover it?

already tried some random solutions from net but none of them helped me.

Tried git clean -fd

also tried git checkout -- <filename>

tried git checkout -- . too.

I am using VSCode

Edit: Note: I Discarded changes on few days back and now I came to know I discarded wrong files.

  • 1
    If you never committed or staged the file, `git` doesn't know anything about it. You won't be able to recover those changes unless you have some sort of system backups available. – larsks Feb 24 '20 at 13:14
  • 2
    Does this answer your question? [How do you undo "Discard all changes" in VS Code/Git](https://stackoverflow.com/questions/43541167/how-do-you-undo-discard-all-changes-in-vs-code-git) – jonrsharpe Feb 24 '20 at 13:14
  • @jonrsharpe No, the question is relevant but tried that solution not worked for me, that file is not in my trash too. Note: I Discarded changes on few days back and now I came to know I discarded wrong files. – Dinesh Choudhary Feb 24 '20 at 13:32
  • Please [edit] to add this information. – jonrsharpe Feb 24 '20 at 13:34
  • you can use this `git checkout -- .` instead of file name use dot(.) This command discards all. – Nayan Sarder Feb 24 '20 at 13:35
  • @NayanSarder already tried. Updated question. – Dinesh Choudhary Feb 24 '20 at 13:36
  • Try to use `git restore .` – Nayan Sarder Feb 24 '20 at 13:39
  • 1
    for this kind of errors use a hourly/daily (incremental) backup tool of the source code directories. But then hourly is also not covering it all (deleted it 20 min ago). Use a file system with file versions like VMS. Each save you get a new file version. – rioV8 Feb 24 '20 at 14:36

1 Answers1

0

If you haven't closed the editor you can try ctrl + z. Have you?

Stevemats
  • 68
  • 7