Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+8 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

Recently, I have been asked to cherry-pick a commit.

So what does cherry-picking a commit in git mean? How do you do it?

1 Answer

+8 votes
by (50.2k points)
edited by

What is cherry-pick?

Cherry-pick in git means choose a commit from one branch and apply it onto another.

How to run cherry-pick?

Make sure you are on the branch you want to apply the commit to.

git checkout master

Execute the following:

git cherry-pick <commit-hash>

Different scenarios of cherry-pick

If you cherry-pick from a public branch, you should consider using

git cherry-pick -x <commit-hash>

This will generate a standardized commit message. you can still keep track of the origin of the commit and may avoid merge conflicts in the future.

If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:

git notes copy <from> <to>

Go through the following tutorial where you can get a better understanding of git:

Git cherry pick- What does cherry-picking a commit with Git mean?
Intellipaat-community
by (19.4k points)
great explanation, can we choose commit from a remote branch?

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...