5

FML..

I worked directly in my Github repo folder while working on a project (don't ask me why). I did my initial commit with all my code from the start until 5 hours ago. I never pushed.. A minute ago, I checked my commit and noticed that there were DB credentials in one of the files. So.. Smart me.. "revert commit"..

Result. Everything got deleted except my node_modules folder and the readme file.. I lost everything.. Fuck me, I'm going home..

Please, someone.. Can I get these files back via git or something? Can't find anything in in the history..

Comments
  • 1
    Actually yes, you might be able to get them back. Give me a sec
  • 1
    First of all - make a copy of the folder containing the git repo, so you can't fuck it up more. Secondly: Did you use git revert? If so that just should be another commit in your history
  • 0
    @Kimmax i tried with recuva, but no success.. I also.. Smart me.. Undid my last change of the commit so the "revert" isn't listed in my git status or checkout.

    + never pushed any commits to that repo
  • 0
    If reverting the revert doesn't work, and git reflog and git fsck show nothing, I'm not sure how to go about this. Try reading up on those commands. A revert is supposed to create a new commit, so I would expect something to be recoverable somehow.

    I did a similar blunder but with git reset before committing anything, so I couldn't manage to salvage anything in that case. It taught me the reason why the initial commit is usually a basic README.

    I understand the frustration you must be feeling right now, but don't lose hope yet.
  • 0
    @Shodan yeah I had a commit doing the revert changes in my history, but I saw my files dissapear, so.. smart me, did an undo of that revert commit, but then it got deleted from my commit history, but it didn't put back my files and now, because there were no pushes, i only have a blanc, fresh repo with only the readme file :D so.. I already gave up, said to my coworker that I'm going home..
  • 0
    Maybe a program to rescue deleted files if nothing else works. Most os does not overwrite deleted files directly.

    Could be messy but may be possible.
  • 1
    As @illusion466 mentioned,. reflog should be helpful.. read abt reflog once..
  • 0
    @Voxera That was my first attempt/reaction. I recovered two small files from that project, all the rest was within a half hour overwritten (due to the ssd I guess)
  • 1
    Got my file contents back! :D Checked the .git/logs/HEAD file. Saw my commit hashes. Did a "git show" in the terminal with that specific hash and it showed all green text of my initial code before the revert and such. Just created the empty files and copy-pasted it, removed the "+" signs and tadaa :D Created a new commit and pushed it immediatly.. "Shame" that an undo of a revert doesn't re-create the files it deleted locally.
Add Comment