{"id":3587,"date":"2011-04-14T14:56:30","date_gmt":"2011-04-14T09:26:30","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=3587"},"modified":"2011-04-14T15:00:00","modified_gmt":"2011-04-14T09:30:00","slug":"git-cherry-pick","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/git-cherry-pick\/","title":{"rendered":"Git cherry-pick"},"content":{"rendered":"<div><strong>git cherry-pick<\/strong> is yet another great feature of git.With the help of this command we can apply the changes in a branch, introduced by an existing commit in some other branch. So, it\u00a0allows to copy commits from one branch to another, but one commit at a time.<\/div>\n<div><strong>Syntax<\/strong> for this command is :- \u00a0 \u00a0<strong>git cherry-pick [&#8211;edit] [-n] [-m parent-number] [-x] &lt;commit&gt;<\/strong><\/div>\n<div>\n<div>Lets take an <strong>example<\/strong> :- Considering two branches master and Feature1 .Now the branch Feature1 had implemented some features,and all these features are not to be pushed to master for now .Lets suppose at this time master requires a single feature from Feature1 branch not all the features.So here the Feature1 branch is not required to be merged to master branch and all the features on Feature1 branch to be applied on master branch, but it requires cherry-picking a single commit from Feature1 branch on branch master.<\/div>\n<div><strong>Step 1:-<\/strong> See the logs of branch Feature1<\/div>\n<div><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace;line-height: 18px;font-size: 12px\">[java]<br \/>\n$ git checkout Feature1<br \/>\nSwitched to branch &#8216;Feature1&#8217;<br \/>\n$ git log \u00a0-12 &#8211;oneline &#8211;decorate &#8211;graph<br \/>\n* ebf6dc5 (HEAD, Feature1) updated movie\/show page and movieReview page so that critic reviews open in a new tab<br \/>\n* 1913561 Implemented A as a new critic rating source<br \/>\n* bfdb04f Implemented B as a new critic rating source<br \/>\n* b173d91 Implemented C as a new critic rating source<br \/>\n* dc72a67 updated criticRating url finder for source D<br \/>\n* \u00a0 475be65 Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR into Feature1<br \/>\n|\\<br \/>\n| * \u00a0 6469926 (master) Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n| |\\<br \/>\n| * | d01398a resolved problems in critic rating url finder for sources F and G<br \/>\n| * | \u00a0 62133e9 Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n| |\\ \\<br \/>\n| * | | 6f614ee resoved conflict<br \/>\n* | | | 76b6da1 Implemented E as a new critic rating source<br \/>\n| |_|\/<br \/>\n|\/| |<br \/>\n* | | 789cbd8 (origin\/master, origin\/Feature1) updated critic rating scraper for source D<br \/>\n| |\/<br \/>\n[\/java]<\/p>\n<div>Here we find branch Feature1 is at commit &#8220;ebf6dc5&#8221; and master is at commit &#8220;789cbd8&#8221;<\/div>\n<div><strong>Step 2:-<\/strong> Checkout to master branch and look at its log.<\/div>\n<div><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace;line-height: 18px;font-size: 12px\">[java]<br \/>\n$ git checkout master<br \/>\nSwitched to branch &#8216;master&#8217;<br \/>\n$ git log \u00a0-8 &#8211;oneline &#8211;decorate &#8211;graph<br \/>\n* \u00a0 6469926 (HEAD, master) Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n|\\<br \/>\n| * 789cbd8 (origin\/master, origin\/Feature1) updated glamSham critic rating scraper<br \/>\n* | d01398a resolved problems in critic rating url finder for sources F and G<br \/>\n* | \u00a0 62133e9 Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n|\\ \\<br \/>\n| |\/<br \/>\n| * \u00a0 174a6b6 (Feature2) resolved conflicts when pulled frm master<br \/>\n| |\\<br \/>\n| | * \u00a0 99e3b0b Resolved conflict<br \/>\n| | |\\<br \/>\n| | * | 9cf6965 Added another config for www<br \/>\n| | * | d241d62 updated www config<\/p>\n<p>[\/java]<\/p>\n<p><\/span><\/div>\n<div><strong>Step 3:-<\/strong> We have to cherry-pick the commit &#8220;dc72a67&#8221; from branch Feature1 and apply the changes to master branch.<\/div>\n<div><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace;line-height: 18px;font-size: 12px\">[java]<br \/>\n$ git cherry-pick dc72a67<br \/>\nFinished one cherry-pick.<br \/>\n[master de7a70a] updated criticRating url finder for source D<br \/>\n1 files changed, 2 insertions(+), 1 deletions(-)<\/p>\n<p>[\/java]<\/p>\n<p><\/span><\/div>\n<div><strong>Step 4:- <\/strong> Now again lets see the logs of branch master to see the changes of cherry-picking.<\/div>\n<div><span style=\"font-family: Consolas, Monaco, 'Courier New', Courier, monospace;line-height: 18px;font-size: 12px\">[java]<br \/>\n$ git log \u00a0-8 &#8211;oneline &#8211;decorate &#8211;graph<br \/>\n* de7a70a (HEAD, master) updated criticRating url finder for source D<br \/>\n* \u00a0 6469926 Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n|\\<br \/>\n| * 789cbd8 (origin\/master, origin\/bollywoodHungama) updated glamSham critic rating scraper<br \/>\n* | d01398a resolved problems in ibn and indian express critic rating url finder<br \/>\n* | \u00a0 62133e9 Merge branch &#8216;master&#8217; of github.com:IntelliGrape\/RATOR<br \/>\n|\\ \\<br \/>\n| |\/<br \/>\n| * \u00a0 174a6b6 (glamSham) resolved conflicts when pulled frm master<br \/>\n| |\\<br \/>\n| | * \u00a0 99e3b0b Resolved conflict<br \/>\n| | |\\<br \/>\n| | * | 9cf6965 Added another config for www<\/p>\n<p>[\/java]<\/p>\n<div>So,here we see that the changes of commit &#8220;de7a70a&#8221; is applied on master branch.<\/div>\n<div>Hope this will help the git users. \ud83d\ude42<\/div>\n<div>Regards<\/div>\n<div>Shweta Gupta<\/div>\n<div>Intelligrape<\/div>\n<p><\/span><\/div>\n<p><\/span><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>git cherry-pick is yet another great feature of git.With the help of this command we can apply the changes in a branch, introduced by an existing commit in some other branch. So, it\u00a0allows to copy commits from one branch to another, but one commit at a time. Syntax for this command is :- \u00a0 \u00a0git [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[554],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3587"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=3587"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/3587\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=3587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=3587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=3587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}