1

Last week I created a new Github repository, and before adding the code there, I created a README.md and commited online only (18 times). This file was never on my local computer.

Today I pointed my current local code to the Github repository, commited and pushed it with my git (hundreds of files). The commit was successful, but for my surprise, the README.md disappeared in the process!

I tried to recover it on Github, but it is not there. The repository shows: 1 commit, 1 branch, 1 contributor. My main page still shows: "Created 18 commits in 1 repository", but I was not able to see it or find this file no matter what I tried.

How can I recover it?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Chaotic
  • 133
  • 7
  • 3
    Sounds like you did a force-push. You should have rebased your commits on top of the original commit on GitHub or done a merge. – Dai Mar 19 '18 at 04:26
  • Yes, that's right, I checked that 'force' push on the commit. :-( – Chaotic Mar 19 '18 at 04:28
  • Does this help? http://pablofabregat.com/git/yes-you-can-revert-a-git-push-force/ – Dai Mar 19 '18 at 04:29
  • I'm not finding the git history with the old SHA key of my commit (#{OLD_SHA}...#{NEW_SHA}), but maybe it is a beginning. – Chaotic Mar 19 '18 at 04:34

1 Answers1

4

As I explain in "Getting a history of which commits were force pushed", you still can have a look at your GitHub repo through the GitHub Events API

You should be able to extract the commit done just before the last one (which was forced, and replaced the local history)

From there, you can go to the URL of that past commit, and get your README.md from there.

janos
  • 120,954
  • 29
  • 226
  • 236
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Got it! That's so fantastic, I was looking for my Chrome cache in order to recover the file, with no avail. Now I was able to get the hash and then the commit and last but not least, the file. Thank you! – Chaotic Mar 19 '18 at 06:13
  • @Chaotic Well done! That is why, by the way, removing a sensitive information can be tricky, as mentioned in https://stackoverflow.com/q/23666879/6309. GitHub support team needs to be involved. – VonC Mar 19 '18 at 07:28