I was on a branch in Git, doing some work. Then I decided to check out one of my previous commits on that branch using the commit's hash, with git checkout -b new_branch 6e559cb
. Now when I enter "git branch" it says that I'm currently on "(no branch)". How do I merge this no-branch into the branch it was split from? Thanks!
Asked
Active
Viewed 60 times
1

fullstackplus
- 1,061
- 3
- 17
- 31
-
what does `git branch -avv` tell you ? – Nevik Rehnel Dec 17 '12 at 12:44
-
* (no branch) 4d0dcb6 tidying up complex e312e49 and now, it's fixed - by using immutable hashes master 2cbaeb9 very basic example, no real parser – fullstackplus Dec 17 '12 at 12:50
2 Answers
1
I am not sure that you did it in proper way (I am assuming that you are working on "new_branch" and you wanted to apply commit from another branch on top of that).
The most convenient way would be do cherry-pick (or merge) commit from one branch to another.
git[new_branch]$ git cherry-pick 6e559cb

Jarosław Jaryszew
- 1,414
- 1
- 12
- 13
-
Yes, I clearly screwed up something. When using your command above, isn't it required that one is on a branch? I'm currently on no branch, so don't know what to use in place of new_branch. – fullstackplus Dec 17 '12 at 12:53
-
1That's not what the OP wants to do. `git checkout -b new_branch 6e559cb` creates (and checks out) a new branch originating from commit `6e559cb`. – Koraktor Dec 17 '12 at 12:54
-
I see. I just used git checkout -b new_branch, without specifying the commit, but it's good to know that option exists. Thanks for the help! – fullstackplus Dec 17 '12 at 13:06
1
If somehow your command didn't create a branch at 6e559cb, you simply can create one now (where you are currently in "no branch", that is "detached HEAD" mode.
git branch new_branch
git checkout new_branch
# or git checkout -b new_branch