简体   繁体   中英

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.

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

provided you didn't delete gh-pages you can do

git checkout gh-pages

and then to recover your work

git reset head~1 --soft

or you may very well merge your branch into master like:

git merge gh-pages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM