-1

Originally on my Github are some outdated styles.css and JavaScript files and others.

I was working on my project last night but didn't push it to Github or back it up. It was just saved in my local repository using a series of local, unpushed commits.

Being a newbie that I am, I did a git pull request master, and all the files in my local repository got replaced with the original styles.css and JavaScript that was in my github.

Is there a way to get those files back?

I did a git reset head@{2} where I believe the state of the repository before the pull request was, and it showed some unstaged files.

In Gitshell my command line has "master [+10 ~19 -42 !]" with the text master being yellow.

At this point, what do I do? Currently I seem to have lost a lot of work.

halfer
  • 19,824
  • 17
  • 99
  • 186
Roger
  • 83
  • 3
  • 9

1 Answers1

2

If you have performed commits often you can pretty much get to any of them.

Use git reflog first (https://git-scm.com/docs/git-reflog). It will show you all the interim commits you've made. Once you find a relevant one you can do git reset #commit_id.

halfer
  • 19,824
  • 17
  • 99
  • 186
amdmax
  • 771
  • 3
  • 14
  • I did a git add and then commit just before the pull request while in gh-pages, not master (forgot to do git checkout master before I closed git shell previously) , and doing a git reflow show, it shows the commit. But when I go to Github.com and navigate to gh-pages, it doesn't show and the files in gh-pages were still the old version. – Roger Dec 04 '16 at 22:17
  • What do I type after doing a reset? Currently the master text is yellow in git shell. I don't wanna go any further on my own – Roger Dec 04 '16 at 22:34
  • If you can see the changes reflected on your local machine (it is up to date) you can push the changes to github by doing git push --force. Otherwise please clarify what the expected endresult is. – amdmax Dec 04 '16 at 23:37
  • 1
    I have fixed it now by doing what you suggested. Do a "git reflog show" to see where I last made a commit. Then using git reset HEAD`{2`} in gitshell. Then I typed "git status" to show which files were modified and deleted. This is the part where I was stuck, not knowing how to get the files in the "git status" list back to my local repository. Googled it and found a solution. It's "git checkout -- ." to recover all the files in the "git status" list back to the local repository. All files on github was left untouched, only the ones that I pulled to my local were recovered. – Roger Dec 05 '16 at 04:16