0

Possible Duplicate:
Lost Last Git Commit
gitx How do I get my ‘Detached HEAD’ commits back into master

I am using GitHub for Mac. I finished committing all of my changes, then realized that I was committing to the HEAD. So I clicked on my master branch, and now all of my commits (and thousands of lines of code) have disappeared. Please help me!

Thanks.

Community
  • 1
  • 1
Garrett
  • 11,451
  • 19
  • 85
  • 126
  • `HEAD` is an alias for the tip of your currently checked out branch. So what branch were you on? I.e. what branch do you mean when you say `HEAD`? Your changes should still be on that branch. – Christoffer Hammarström Dec 22 '12 at 01:18
  • I used http://sitaramc.github.com/concepts/detached-head.html to find the command `git reflog show HEAD@{now} -10`. Sorry for the thoughtless post, I think we all know how scary it is to lose so much work... now I'm just trying to merge to my new branch. I've copied the commits to a new branch, `master2`, but really want them on `master` – Garrett Dec 22 '12 at 01:22
  • I see it is a duplicate. My bad. Weird that it didn't come up in my related questions. – Garrett Dec 22 '12 at 01:24

1 Answers1

4

There is always "git reflog" to find old commits.

If you have not committed anything since then

git branch old-commits HEAD@{1}

should create "old-commits" branch that contains your old commits.

Then you can merge or rebase those commits on your master.

user1922076
  • 136
  • 1