Alex Zaitsev
Alex Zaitsev

Reputation: 1781

How to move certain commit to NEW branch

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

Upvotes: 3

Views: 122

Answers (1)

Simone Carletti
Simone Carletti

Reputation: 176352

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

Upvotes: 2

Related Questions