On Fri, Jul 6, 2012 at 3:55 AM, lem torov <ulem...@gmail.com> wrote:
> i was using netbeans ide and as CVS i was using git included into IDE.
> once i lanch standalone git-msys in my project directory
> git branch
> showed me
> * no branch
> you are not in any branch
> i did
> git checkout master
> and i lost like 5 weeks of my work. if there is any way to restore it?
If I was a jerk, I would give you the accurate-but-unhelpful advice
that you should run the command Git told you to run in the warning
message it printed when you did 'git checkout master'.
If I was trying to be helpful I might try to teach you what a detached
HEAD is and what the reflog does, but that misses the fact that you're
panicking about losing five weeks worth of work and not interested in
learning anything until you've found it again.
So I'll give you a step-by-step:
$ git checkout master
Because I'm assuming you want these commits you're trying to
recover to be on the 'master' branch.
$ git reflog
Look in the output for the commit message of the last change
to the branch you're trying to restore
$ git reset --merge abc123
Here, 'abc123' is the sha1 of the commit you noted in the
previous step. You can replace '--merge' with '--hard' if there are
no changes in your current working directory that you want to
preserve, but I'm recommending the safer option for people who find
this post on Google in the future. :-)
That will leave the 'master' branch pointing at the commit 'abc123'.
(In Git, branches and tags are simply pointers to specific commits.)
Now in the future, if you 'checkout' anything other than a branch,
remember to 'checkout' a branch again before you commit anything you
want to keep!
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.
You received this message because you are subscribed to the Google Groups "Git
for human beings" group.
To post to this group, send email to firstname.lastname@example.org.
To unsubscribe from this group, send email to
For more options, visit this group at