0

(referring to this:) Reset all changes after last commit in git

So, I don't have the 50 reputation needed to comment on that topic, so i guess, i have to ask here. In IntelliJ I did follow the first comment saying to git reset HEAD --hard and then git clean -fd. And then I lost all my files.

Nothing is visible anymore in IntelliJ. I can still see the git log, but yet, even after checking out to master and trying to get back to the last commit, I still lost all my files since git clean -fd. If i'm checked in on the branch i want to be, i'm in detached head state.

What can i do? Greets

talex
  • 17,973
  • 3
  • 29
  • 66

1 Answers1

0

git reset --hard HEAD followed by git clean -fd will indeed delete files and modifications which aren't stored in git -- and it looks like you didn't anticipate that.

Unfortunately git will not help you recover those files, you will have to turn either to your IDE (I think IntelliJ keeps history of its own for files you saved through your IDE ?) or to a file recovery tool for your system.


Regarding what was committed before that, however (such as : what was committed on master) you should be able to tun git checkout master (or the equivalent action from IntelliJ) with no problem

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • @JuliusCicero : This answer is just a generic answer to a would be "how can I recover files deleted with `git reset --hard` and `git clean -fd` ?" question, but you seem to have a point with something more precise ; if this is the case, could you please add more details to your question, about what your initial intention was, and what doesn't work anymore now ? – LeGEC Jul 05 '21 at 16:42
  • Thank you for your patience. I think, at this point it would be easiest if i just downloaded the state of the repo from GH and go on from there. How do I do that? – Julius Cicero Jul 23 '21 at 09:13
  • @JuliusCicero : for a complete reset : clone again ; for an update of your local repo : `git pull`, or `git fetch` and inspect the state of your remote branches to choose which one you should `git reset` to – LeGEC Jul 23 '21 at 09:45
  • Since I'm doing this with IntelliJ, i have to log in GH. But for my GH Account i use GMAIL-adress, but the formular is the password for the @github.com adress, though i never verified this. What can i do now? – Julius Cicero Aug 03 '21 at 12:05