So, backstory. My hard drive died on machine A. Almost all of my work was already pushed to GitHub and all was dandy on that front, save one repository. So, upon realizing this, I found out, "hey, cool, I actually just sent a tar file of the most recent changes to Guy Guyerson anyway." So I get the tar file and then do something stupid/show how much of a GitHub noob I am. Instead of cloning the repository then adding the updated files, then pushing, I think to myself: I should be able to just push these files, no problem. So I git init,add the remote and then push, but it doesn't work... because the merges are strange. I know about the merges being bad, so I decide to force these files to update and push -f. However, since this is a new .git directory, the push overwrites everything and I lose my entire commit history and all the files that weren't in the tarball are gone.

Is there anyway to get back to that, given that the current local version has no memory of there every being previous commits? I have the beginning of the hash that it overwrote, but the remote has no memory of that commit now either.

I think that the HDD crash may have claimed another victim, as my frustration boiled over and I just wanted to push the updates while I still had them on this older machine.

Thanks, Zach

  • What environment are you working in? Is this Eclipse??? Java ??? – Dale Jun 8 '16 at 20:02
  • Sorry I don't understand why the environment matters, but I'm working from terminal in Linux (though the original machine was a Mac). The code was all C++ based. Luckily, the only contributor to the project is me, so it's not a big loss other than the hours of work I'd put into the macros that I've lost right now. – Zach Jun 8 '16 at 20:12
  • Here's why it might matter. I've had something like this happen to me in Java using Eclipse. I've in fact had files DELETED that were not saved. Mind you I did know the file that was deleted and where it was. Eclipse keeps a history of that file even if it is deleted. So what I did was recreate the file as a blank file where it existed before and then right clicked on it and looked back in history to what was in it. Then I restored it from Eclipse's history. That's why environment might matter. – Dale Jun 8 '16 at 20:14

The online version of GitHub does keep a record of those old commits, I just didn't know how to access them. For any future readers: if you have the commit ID you accidentally overwrote you can access it like this:


From there, you can use the Tree/Branch dropdown to create a new branch from that commit. This can then be cloned to a local directory and then you can merge, etc from there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.