I put my local repository on github. In the github repository, I created README file by clicking the "we recommend a README file link". I wrote a detailed content in it and committed it. But I did not clone this file into my local repository. Recently, I made some changes and pushed them to the github repo. Today I noticed that the README file is missing. I checked my commits and couldn't find anything related to README there.
I am using Eclipse egit plugin to interact with the github repository. I did click on "synchronize workspace" in Eclipse "Team" menu, just to check what it does - this is before I noticed that the file is missing.
Is there anyway to retrieve my README.md file? Please let me know.
My repository: https://github.com/raghavam/d-sparq
From the comments, the original poster says:
Yes, I did tick an option called "force push" in Egit because without that it was giving me an error. What does a force push do when compared to a regular push?
But, I haven't done a fetch or pull - I don't generally do that because I am the only one using that repo and so my current local copy would be the latest.
Yeah, it definitely sounds like you ended up force-pushing your local copy of your repo, which then overwrote the changes you made to your README file on GitHub, especially since you say that you never fetch or pull.
The problem with never fetching or pulling is that you describe editing and committing a README file through GitHub's web interface:
I created README file by clicking the "we recommend a README file link". I wrote a detailed content in it and committed it. But I did not clone this file into my local repository.
So your remote repo has commits that your local repo doesn't. That's probably the error message you were getting when you tried to push, something along these lines, right?:
git push origin master
# To https://github.com/user/repo.git
# ! [rejected] master -> master (non-fast-forward)
# error: failed to push some refs to 'https://github.com/user/repo.git'
That message basically means that you need to merge the remote commits with the work in your local repository. But instead of doing that, you just completely overwrote those commits to the README file (that you did remotely) by using force-push, which you should not have done if you didn't really understand what it does.
Be very, very careful with force-push. Only use it when you understand what it does and you're sure that using it is what you want to do, because it's one of the most common ways for Git beginners to end up losing work.
Since you never fetched or pulled from your repository, the file is basically unrecoverable now, because it was never downloaded to your local remote. You'll need to start over.