What should i do in order to get the old code back?
I was working on my repository as usual.As i am new to GitHub i pushed my code 3 days ago.
Today in order to push the code i pulled it and my entire repository got replaced with old code.
All i did was using the below commands
git add .
git commit -m "your_name"
git remote add github *repo_link*
git remote -v
git push -f github repo_name
Please provide a solution so that i can i get my old code back.
As you explained above, you forced push (git push -f
) an old branch to the remote, effectively overriding whatever was there, so there are not many options left other than:
1-) Check if you still have the commits on your repository, on a different branch. In your code above you added a remote called github
. If you originally cloned the repository from GitHub before, you might have your old branch in the origin
remote (e.g. origin/master
). In that case do a git checkout origin/master
to see if your old code is still there
2-) Check if anyone else has a clone/fork of your repository with the old code and get a copy of that
3-) Try to recover the lost commit(s) using git reflog
4-) Try contacting GitHub and see if they can restore your repo to a previous state