Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 953
rocknow Avatar asked Dec 13 '25 19:12

rocknow


1 Answers

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
like image 70
Simone Carletti Avatar answered Dec 15 '25 13:12

Simone Carletti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!