0

I was working locally on a branch that seems not to be tracked (it said:"No-Branch"). I made a ton of commits, everything was going great. but then I checked out master to merge my branch. And the branch dissapeared.

Is there any way to retrieve it ?

@FIX (Knittl):

"git reflog" showed me something like

  • f85d248 HEAD@{0}: commit: Modal loader fixes
  • e17e71b HEAD@{1}: commit: Module updates
  • 3fcb3d6 HEAD@{2}: commit: Updated rules
  • dc99963 HEAD@{3}: checkout: moving from 582315b9104af7e8525857b74e5b74aed7c86c54 to master

So I did "git checkout 582315b9104af7e8525857b74e5b74aed7c86c54"which put me back on the detached head.

Create a branch and merged with master

Thanks a million @knittl for saving my ass with providing the right help.

4

1 回答 1

1

You weren't on any branch (that's why it said no branch). There's no such thing as an "untracked branch", you probably mean detached HEAD.

Run git reflog, you should see your commits there. Create then a new branch for the commit you need (e.g. git branch my-feature HEAD@{1})

In case you ever find yourself on a detached head again, you can simply run git checkout -b my-feature to create a new branch at the commit you are currently at. That way the commits will become reachable and are not going to be garbage collected. The reflog is usually only maintained for 30 days and entries older than that can get deleted any time.

于 2013-09-20T11:43:52.440 回答