I accidentally force push my local file

I edit README.md of my repos online (Which was never be pulled to local).

And in my local there were README.md that contain only 1 line.

Then I accidentally force push from local and my online README.md was overwrite from the local one.

Are there anyway to recover this?

I have tried this but I can’t find the HEAD{x} that contains my README.md online


1 Like

Hey @paraduxos, thanks for being here. Please see here: https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/ for a guide on how to undo almost anything with git. 

Let me know if you have any follow up questions. 

Hi, I have exactly the same issue but I can’t seem to figure out what section of this guide should help me.

I made some changes to my README.md on the 18th. I didn’t pull them down to my local repository. I then made some local changes, committed them, then force pushed to the repository (because I’m an idiot, and couldn’t understand why there was a conflict). Now if I look in the history of my README.md online, it shows only the older commits. There is no record of the changes I made. I know that the forced commit was one of two commits, made on the 18th or the 20th.

I tried reverting to one of these commits on my local, but that hasn’t made any difference. I tried cloning the repository and running fsck --full --lost-found, but nothing was found. I can’t see how any of the other suggestions in your link help in this case.

Anything I can do, or do I need to re-do my README.md?

I’m afraid you’ll probably have to re-do the README. Overriding remote-only commits on the pushed branch is exactly what a force push does.

I see two other options that might theoretically work, but I have no idea what the chances of them working are:

  1. If you know someone who might have fetched the repository in between, the commit might still be around on their system. If anyone complained what the force push was about they’d be a prime candidate. :wink:
  2. You could try asking GitHub support if they might be able to pull it from a backup.