Undo 'git push -f' from machine that doesn't have the cloned history

0

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

Zach

Posted 2016-06-08T19:52:03.507

Reputation: 101

What environment are you working in? Is this Eclipse??? Java ??? – Dale – 2016-06-08T20:02:38.297

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 – 2016-06-08T20:12:00.067

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 – 2016-06-08T20:14:54.910

Answers

0

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:

https://github.com/userName/repoName/tree/commitNum

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.

Zach

Posted 2016-06-08T19:52:03.507

Reputation: 101