How to merge a commit from another branch to my current branch in git?

Posted on In QA

I have 2 branches: dev and master.

I have commits in dev like this:

c0-->c1-->c2-->c3-->c4

Commits in master like this:

c0-->c5-->c6

c2 and c3 fix a bug.

Now, I want to merge commit c2 and c3 that fix the bug to the master branch, but I do not want to merge all the commits (e.g. c4).

How to merge these specific commits from a branch to another branch?

For this purpose, the command git cherry-pick is very useful.

If the c2 and c3 are the SHA1 object name (40-byte hexadecimal string). (more commit format of git):

git cherry-pick c2
git cherry-pick c3

Of course, you should merge some commits when it is needed and resolve the conflicts.

Leave a Reply

Your email address will not be published. Required fields are marked *