Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I merge 1 commit from a branch to another branch

Tags:

git

I switch to a branch (branch1) in git and I did multiple commits there in that branch. And now I switch to another branch (branch2), how can I merge 1 (the latest in branch1) to this new branch (branch2)?

If I do 'git merge branch1' when I am in branch2, i will merge all commits I did in branch1. I do not want that i only want the latest one.

Thank you.

like image 993
michael Avatar asked Feb 25 '23 06:02

michael


1 Answers

You want:

$ git cherry-pick COMMITID

See the git cherry_pick man page:

Given one or more existing commits, apply the change each one introduces, recording a new commit for each.
This requires your working tree to be clean (no modifications from the HEAD commit).

like image 77
MikeyB Avatar answered Feb 28 '23 07:02

MikeyB