4

Fairly new to GIT and need a little help.

Hosting my content on Github. Last night I realized I hadn't pushed my content up to Github in awhile so I opened up the github mac client and did a commit/sync on my project. It said I was 2 commits ahead of the master branch. I was confused...

1st Mistake - So I did a " git reset --hard origin/master", I then synced up with Github.

I open up my laptop the next morning, then open up netbeans and all my work that I did is gone. I'm in panic mode...

So I'm Googling around and find this page which describes how to undo a GIT Reset. I followed that pretty well and reset to the previous commit. Here is my Git relog:

ce8d01b HEAD@{0}: reset: moving to HEAD@{1}
fcc0db9 HEAD@{1}: commit: front page
ce8d01b HEAD@{2}: reset: moving to origin/master
a6bda3a HEAD@{3}: commit: front page
cde0712 HEAD@{4}: commit: Fixed Front Page Slider
ce8d01b HEAD@{5}: commit: Fixed Company Scrolling.
dd7b163 HEAD@{6}: commit: Work on company product and home page
4cc4274 HEAD@{7}: commit: Added Company Page
1ebed75 HEAD@{8}: commit (initial): initial

After I did git reset HEAD@{1} I opened netbeans and the code still wasn't there so I thought maybe I did the wrong one. So I did it again but this time went to HEAD@{2}. Which is where I am now.

a6bda3a HEAD@{0}: reset: moving to HEAD@{3}
ce8d01b HEAD@{1}: reset: moving to HEAD@{1}
fcc0db9 HEAD@{2}: commit: front page
ce8d01b HEAD@{3}: reset: moving to origin/master
a6bda3a HEAD@{4}: commit: front page
cde0712 HEAD@{5}: commit: Fixed Front Page Slider
ce8d01b HEAD@{6}: commit: Fixed Company Scrolling.
dd7b163 HEAD@{7}: commit: Work on company product and home page
4cc4274 HEAD@{8}: commit: Added Company Page
1ebed75 HEAD@{9}: commit (initial): initial

But I still can't see my code. Is there something else I need to do?

Thanks for the help

DaveG
  • 1,203
  • 1
  • 25
  • 45
  • 1
    Which commit had your code in it? It looks here like it might be `a6bda3a`, but you say you don't see your code? Did you try `git checkout @{6.pm.yesterday}` or something like that to just go back to a particular point in time? – Carl Norum Feb 01 '13 at 18:21
  • Ok so from your comment Carl. If I now do a git reset HEAD@{4}. Do I need to do a git checkout to see the code or should it populate correctly after doing a git reset? – DaveG Feb 01 '13 at 18:37
  • Why are you so set on using the `HEAD@{4}` syntax? What's wrong with using the hash or the time-based example I gave? – Carl Norum Feb 01 '13 at 18:39
  • Ok gotcha did a git checkout @{3.pm.yesterday}...didn't revert back to my code – DaveG Feb 01 '13 at 18:45

1 Answers1

2

From your reflog, a

 git reset --hard a6bda3a 

should restore your content as it was before your git reset --hard origin/master.

Then, if GitHub branch is ahead, I would recommend a:

git pull --rebase 
# check everything is still working
# git add and git commit if needed
git push
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • VonC...thanks for the help. I tried this as well...didn't work. – DaveG Feb 01 '13 at 18:52
  • @DaveG you mean a6bda3a isn't the code as committed before your first `git reset --hard`? Don't forget that this command removes any private files and reset the index. So did you had uncommitted work? – VonC Feb 01 '13 at 18:56
  • yes, I reverted to a6bda3a and it's not the code. I'm thinking I had uncommitted work...Stupid mistake. There is one saving grace I think. (Forgive me since I usually use the GUI instead of the command line). I now open up the GITHUB GUI and it says I have unsynced commits from 18 hours ago. I'll happily revert to that one. I'm just not sure how to switch there. My alternative is a commit 2 weeks ago :) – DaveG Feb 01 '13 at 18:59
  • @DaveG would http://stackoverflow.com/questions/8174324/github-unsynchronized-commit help? Or http://stackoverflow.com/a/13117323/6309? Did you try a `git stash pop`, just in case the GUI did save your work in progress? – VonC Feb 01 '13 at 19:05
  • @DaveG Any time machine feature activated on your Mac which could allow you to get those files back? – VonC Feb 01 '13 at 19:10