0

My whole week of work is gone. This is what happened:

I haven't updated my github for a week. And I added a lot of stuff, so just now I decided to open window git gui. Did a stage, then commit, then push. Then I remember when I pushed I had an error window name push_setup already exist.

After that I closed everything (including my Atom editor) and did a git gui push again, and it said everything was up-to-date. I then check github and nothing was changed. Then I did the following on cmd git without thinking cause I was too tired

git checkout quoteBranch   
git merge quoteBranch  

I must have overwrote everything. What should I do, someone help. Sorry if my wording are messy, Im in a panic. Please someone help, please is there a way to reverse

1615903
  • 32,635
  • 12
  • 70
  • 99
user308553
  • 1,238
  • 4
  • 18
  • 32
  • 1
    Do not panic. Your work is not lost and if you proceed carefully you should be able to recover everything. – Jonah Apr 25 '16 at 22:33
  • 2
    Read this full answer for some other options if you run into detached HEAD when you restore commits with reflog. http://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location/34519716#34519716 – CodeWizard Apr 25 '16 at 22:38
  • omg thank you i got my files back!!!! – user308553 Apr 25 '16 at 22:44

1 Answers1

4

First of all check your log to see if you have your commits in the log.
If not use the ref log below.

You can recover any content which was added to the staging area even if you did not commit.

Git track content when its added to the staging area so it can be restored.

Here is where git reflog is come to rescue you.

git reflog

git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.

Every time the HEAD is modified there will be a new entry in the reflog

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit

enter image description here


Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • Hi so I did relog and got a lot of Head as shown. Do I just do git checkout HEAD@{1}. if the HEAD{0} is the one that deleted everything?? – user308553 Apr 25 '16 at 22:36
  • `git checkout` will get you a "detached head", you probably want `git reset`. – Dietrich Epp Apr 25 '16 at 22:37
  • Find out which one was the last good one and check it out. it should be one of the first ones i assume, since you did it just now. – CodeWizard Apr 25 '16 at 22:37
  • so I should do git reset HEAD@{1} instead? – user308553 Apr 25 '16 at 22:40
  • Agreed. here is how to fix a detached head http://stackoverflow.com/questions/34519665/how-to-move-head-back-to-a-previous-location/34519716#34519716 – CodeWizard Apr 25 '16 at 22:40
  • 1
    You need to find out which one you need. read the reflog and go back to the point before the merge, – CodeWizard Apr 25 '16 at 22:40
  • omg thank you so much I got my files back. I was freaking out my brain wasnt functioning. I thought i lost everything, I should really read the doc properly before I do anything – user308553 Apr 25 '16 at 22:44
  • Cool, glad to help. Read the full answer above to learn more about detached HEAD. – CodeWizard Apr 25 '16 at 22:56