Menu

How to cherry pick multiple commits from a branch to other?

It is very common practice to pull push and merge the changes from one branch to other branch for developer. Today we are going to see how we could cherry pick changes from one branch to other branch or from feature or working branch to master. Some times we come at a situation where we do not want to merge the complete branch into another branch, instead of complete merge or pull we just want to merge few commits from one branch to another, for that we have cherry pick option in git.

for example we are currently working on branch feature/fix01, and n commits are available on fix01 branch.
Now we want to cherry pick only commit A and B to master branch. to do so, please do the following steps.

Step 1: Open git bash.
git checkout fix01
git log
 $git log command will show all commits, with commit details. From here you can take the commit ID. Alternate to get the commit ID is from git UI, check for the commit SHA. As shown in below screenshot.

 
Step 2: Now checkout the master branch where we need to push the commits.
git checkout master
Step 3: Now run the cherry pick command
git cherry-pick a001 b001 // here a001 and b001 is commit IDs for A and B commit respectively.
if cherry-pick command didn't run successfully and halted due to some conflict, then go to repo and fix the conflicts and then came back to git bash and run the cherry-pick continue command.
git cherry-pick --continue

if you want to stop the cherry-pick or end the process, then run cherry-pick abort command.
git cherry-pick --abort

Step 4: If you cherry-pick was successful then run the git push to move the commits.
git push origin master/master
Step 5: Verify the changes.

References:




No comments:

Post a Comment