2

I accidentally did a git reset --hard origin on my local repository. As a result, all of my changes have been reverted back to their original state, hence my months' worth of code and work is gone. I didn't do git add on my repository so literally, any changes I've made on my repository are gone without a trace. I've tried searching for a solution but I've only seen answers that pertain that you can only recover your work if you do git add to it.

Any help is greatly appreciated. PLEASE DO HELP ME, GUYS.

Raaald
  • 51
  • 5
  • 1
    Sorry to say but it's gone. You literally said, "revert _all_ files back" running that command. I hope you've learned and know how to redo what you undid. – Jeff Mercado Aug 05 '21 at 01:41
  • 2
    if you didn't at least run `git add`, git won't be able to help there. You depend on other resources like IDE cache, for example. – eftshift0 Aug 05 '21 at 01:44
  • 2
    You made months worth of changes without committing? Anyway, if you haven’t already, stop using the computer. Plug the hard disk into another device and run file recovery software. – Ry- Aug 05 '21 at 03:30

1 Answers1

1

Beside running a file recovery utility, as detailed in "Can I restore deleted files (undo a git clean -fdx)?", check your IDE.

Some of them keep a local history (IntelliJ IDEA, VSCode through an extension, ...): you might get back some of your files content that way.

But yes, regular add and commit, even for a work in progress, is a best practice.
A regular push to a remote "work-in-progress" branch is equally good, to save your work to an external referential.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250