-1

This is my final assignment for my course. I worked really hard on it, and was supposed to push the files to a git repository. I tried doing so and it failed, I believe I pressed revert afterwards, it did nothing.

When I went to check to my local repository, my usual files were gone, I got two new hidden folders vs. and git. I can find the debugged .exe file which runs okay, but I really need my code back.

Is there any way to retrieve it?

More info: my .cpp files are now .obj files, I can't find the .h files, there are also .exe.recipe files, and some .idb and .pdb files in the folder.

lzhh
  • 852
  • 7
  • 16
  • If you committed and reverted, just revert once more (revert the revert). If you however you ran `git reset --hard`, I'm afraid you lost your files for good. (The only hope could be looking into your computer's shadow copies using ShadowExplorer.) – CherryDT Dec 20 '21 at 21:27
  • "I pressed revert afterwards, it did nothing." Unlikely. Reset, which a GUI wrapper may label Revert, is very capable of deleting any files not correctly committed, depending on the arguments you used. – Ben Voigt Dec 20 '21 at 21:27
  • That's why I always have two directories, the real directory that contains the repo, and an offline "repo-copy" directory that I work on and make changes. – PaulMcKenzie Dec 20 '21 at 21:31
  • 3
    First thing is to have a look at the reflog. Maybe this link could help: https://ohshitgit.com/ – Philippe Dec 20 '21 at 22:48
  • @CherryDT ShadowExplorer got me excited at first, only to find out that it's found an old version of the project, the first day save, that contains <5% of the code ): . Thanks for your reply – JohnAndom Dec 21 '21 at 10:55
  • @BenVoigt I user Visual studio's git tool for this. After the push failed, I pressed REVERT. – JohnAndom Dec 21 '21 at 10:55
  • @PaulMcKenzie Lesson learned. – JohnAndom Dec 21 '21 at 10:56
  • @Philippe it didn't help. – JohnAndom Dec 21 '21 at 10:57
  • What's the size of the `.git` folder? Maybe there _is_ some of the code left there. It still does sound like you committed but then reverted the commit, so reverting again should fix it (or checkout out the previous commit from the reflog as Philippe suggested). Can you show the output of the `git reflog` command? – CherryDT Dec 21 '21 at 11:58
  • If the commit succeeded and only the push failed, then Git should have a copy still – Ben Voigt Dec 21 '21 at 15:22

1 Answers1

0

I managed to retrieve my original files by using git reflog, followed by git reset —hard Head@{n}, and then git retrieve for each file.

Thanks everyone.

Constantine
  • 650
  • 9
  • 15