0

I executed the command git checkout -f branchName on my terminal. That made all of the changes to files I have been working on for four days go away, as I have overwritten them.

The worst part is that I didn't save my files anywhere, nor did I commit previous changes. Is there any way out from this situation? Can I restore my lost files and changes?

codesnerd
  • 767
  • 2
  • 8
  • 23
Benjamin
  • 1
  • 1
  • 1
    no, if the files or changes weren't committed or stashed you cannot retrieve them – Arkadiusz Drabczyk Feb 26 '21 at 23:54
  • One of the answers I was looking for... Now I atleast now that I have to start over again... Nevermind. Thank you for you answer, and even thought it doesn't look like that, it was really helpfull for me. – Benjamin Feb 27 '21 at 00:08
  • In general, the `-f` (or `--force`, if you want to spell it out in longhand) means, in Git: "do something Git can't fix for me". If you have a mac with Time Machine running, that's an example of one way to recover files that *doesn't* involve Git, that might work here. For other systems, there may be something similar. But the force flag here told Git: *please go ahead and destroy my work* and now Git can't undo that... – torek Feb 27 '21 at 07:33
  • Yep, I realised that, but too late unfortunately. I knew that --f means force, but I thought it will do completely another thing, since i thought I was on master branch, and I wanted to go to feature branch. But actually I was already on my feature branch, and with that command I just pulled all the changes from github directly (where I didn't have my changes). But anywas, i rewrote the whole code, and on the bright side, practised some more Vue.js, and learned what git checkout -f does – Benjamin Feb 27 '21 at 11:31

1 Answers1

0

I have no idea why you didn't push your changes, but you can try this solution. I also recommend using Sourcetree to manage your repo.

The last resort might be trying a file recovery program like Recuva.

codesnerd
  • 767
  • 2
  • 8
  • 23
nikitastrike
  • 101
  • 1
  • 8
  • Because I'm crazy... I think nothing will work, and I'll just have to do it again. Thank you anyways for answering my question! :D – Benjamin Feb 27 '21 at 00:06
  • Sure, hope you can recover your files soon, you should use an **IDE** or **text editor** with auto-backups too, so if it happens again (that i hope doesn't) you can always look on the `backups` folder, like Notepad++ – nikitastrike Feb 27 '21 at 00:10
  • Yeah, that's definitely a next thing I'm doing after i finish this project. People are telling me for a longer period of time that VS code sucks, but i guess I had to learn it the harder way hahah... – Benjamin Feb 27 '21 at 00:11