0

I originally made an attempt to remove a local commit by typing git checkout ####### <---- being the first 7 digits of the commit

From there it put me in some Detached Head state of some sort where it would say Detached Head and the commit ########. I didn't realize this so I kept commiting locally as normal. When I went to go push it to github using 'git push origin master' it said everything was already up to date.

I without realize it switched back to master by typing in git checkout - and now I'm back in my master branch with those previous commits not showing up in git log that I did before I switched back to my master. Now that code won't appear on my GitHub even if I try making new edits/commits to my GitHub, so it's out of sync so-to-speak. How do I get those commits back and sync my Github properly?

bahrep
  • 29,961
  • 12
  • 103
  • 150
Jamie22
  • 424
  • 4
  • 15
  • See http://stackoverflow.com/questions/7124486/what-to-do-with-commit-made-in-a-detached-head?rq=1 – torek Jun 02 '16 at 17:44

1 Answers1

0

Take a look at

.git/logs/HEAD

Maybe the following command should help

cat .git/logs/HEAD |grep checkout | head -1

This should print out something similar to this.

15a5345eadd7d3737a3651faf4c142e2c6e23cf4 c4092cb8b80c43b120f33c2b095c1a71a56dd359 Your Name <your@email.com> 1367828297 +0200      checkout: moving from master to c4092cb8b80

The first hash on the line is the commit you lost.

Try

git checkout the_hash
git checkout branch_with_lost_commits

Now you should be on a new local branch containing your lost commits.

murraybo
  • 895
  • 8
  • 13