开发者

So Many Commits to (no branch)

By mistake I have made many days of work's commits to no where. When I checked the current branch git replied me with a (no branch).

I in fact was under the impression that I was committing to开发者_开发技巧 a new branch (other than the master), and everything is going fine. Now when I traverse back and check for the branch of even a very old commit (about a month back) still git says it is in no where (i.e. no branch).

I know that merging will help if it is only one commit. Now how am I to get all the previous commits merged with the master?

Thanks in advance.


When you do checkout to "no branch" git says:

You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example:

git checkout -b new_branch_name

Of course you could merge as much commits as you want.

To find a detached head if you lost it you can use git reflog.

Also you should remember that a detached head could be garbage collected.


You probably committed on a so called "detached HEAD" (for example after git checkout abc123ef).

If you know the commit you committed last (i.e. the HEAD of your "lost" branch), you should be able to reset the branch to this commit and everything will be fine: git branch -f some-branch cbd131ef.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜