I have commit X and 2 commits after it. I should move only X to new branch. How can I do this?
(And my repo is in remote repo also, I don't think exactly what is it, but I won't get "detached head")
Thanks a lot
1 Answer
If commit X is the only commit you want to port to the new branch and the branch is new, simply start the new branch from that commit.
$ git branch newbranch COMMIT_HASH
If you want to move commit X to an existing branch and commit X doesn't necessary fit the branch history, then you can cherry-pick the commit
$ git cherry-pick COMMIT_HASH
-
Thank for your answer. If I'll use "git branch newbranch COMMIT_HASH" will the commit be deleted from current branch (master for me)? Commented Oct 1, 2012 at 17:17
-
@Metalex No it will not be automatically deleted, it'll just create a new branch starting at that commit. To remove it you'll have to use the
rebase
orrevert
command.– RomanCommented Oct 1, 2012 at 17:32