Search code examples
gitgithubversion-controlgithub-pages

Lost github commit to gh-pages when checkout master



After working on a repository in my computer i've opened the terminal to commit the changes to the github account with the purpose of updating the gh-pages branch (after 4 days of work).
I did not notice that I was on gh-pages branch already when a did the git status so I did as if I where on branch master.That is what I did:
1. git add -A
2. git commit -m "message"
3. git push origin master
After this I noticed that I was doing this in the gh-pages branch so I thought (not very cleverly) that i should go back to branch master to do the commits also there and then i did git checkout master. In that moment all my files (my local files, in my computer) went back in time!
The terminal showed a commit number when I did the first commit [gh-pages 4108d5a] but i can not find it in the github history.
Is there a way to recovery the previous state in my local files?? Thanks.


Solution

  • It looks like you pushed to the wrong branch, and then changed branches. You should be able to do this:

    git checkout gh-pages

    git push origin gh-pages

    and all of your work should still be on gh-pages. The master branch is right where you left it back in time. But nothing you mentioned should have removed from your gh-pages branch.

    A good resource to get comfortable with how git branching, merging, etc... work is learn git branching