{"id":4942,"date":"2016-03-01T14:32:44","date_gmt":"2016-03-01T18:32:44","guid":{"rendered":"http:\/\/www.dr-chuck.com\/csev-blog\/?p=4942"},"modified":"2016-03-01T14:32:44","modified_gmt":"2016-03-01T18:32:44","slug":"git-cherry-pick-a-sequence-of-commits-from-one-branch-to-another","status":"publish","type":"post","link":"https:\/\/www.dr-chuck.com\/csev-blog\/2016\/03\/git-cherry-pick-a-sequence-of-commits-from-one-branch-to-another\/","title":{"rendered":"Git cherry-pick a sequence of commits from one branch to another"},"content":{"rendered":"<p>I finally figured out how to pull a sequence of commits from one branch to another using git&#8217;s cherry-pick feature.<\/p>\n<p>In Sakai, when we are preparing for a release, we make a release branch for the release (11.x) and then continue to move master forward and cherry-pick from master back to the release branch.  We looked at git-flow and decided against it because most of our adopters use source and not binary artifacts so our release branches live 4-5 years in production we cannot have master &#8220;jumping versions&#8221;.<\/p>\n<p>So the question is how to cherry-pick back a set of commits to a folder from the baster to the release branch.  This is how I do it.  First go into master and go into the folder of interest.<br \/>\n<code><br \/>\ngit checkout master<br \/>\ncd basiclti<br \/>\ngit log .<br \/>\n<\/code><br \/>\nCapture the log until you find the commit that made the branch.<\/p>\n<p><code>commit 8cc25781d632e48bfae65009b57c6391d074a3d0<br \/>\nAuthor: Charles Severance <csev@umich.edu><br \/>\nDate:   Mon Feb 29 23:03:28 2016 -0500<\/p>\n<p>    SAK-30418 - Initial commit of IMS Content Item<\/code><\/p>\n<p><code>commit 791b12634164003b7c1a59747c28ec9896fc0885<br \/>\nAuthor: Charles Severance <csev@umich.edu><br \/>\nDate:   Sun Feb 28 23:26:51 2016 -0500<\/p>\n<p>    SAK-30372 - Fix small mistake in the CASA output<\/code><\/p>\n<p><code>commit 13d21ccd26901c5186a709be27ede499d7de65fc<br \/>\nAuthor: Charles Severance <csev@umich.edu><br \/>\nDate:   Sat Feb 27 11:27:12 2016 -0500<\/code><\/p>\n<p><code>    SAK-30372 - Switch the implementation to Jackson<br \/>\n...<\/code><\/p>\n<p>Then I cut and paste the entries in reverse order and make a shell script by changing some bits to a comment and changing the commits to &#8220;git cherry-pick&#8221; &#8211; the script ends up as follows:<\/p>\n<p><code># To revert, if some cherry-picks go bad<br \/>\n# git checkout 11.x   (to be extra sure)<br \/>\n# git reset --hard 11.x<\/code><\/p>\n<p><code># After all is verified<br \/>\n# git push origin 11.x<\/code><\/p>\n<p><code># Make sure to be in 11.x first<br \/>\ngit checkout 11.x<\/code><\/p>\n<p><code>git cherry-pick aff5c0343b419fda125d9c217d340bb660929c3c<br \/>\n# Author: Charles Severance <csev@umich.edu><br \/>\n# Date:   Fri Feb 19 09:49:23 2016 -0500<br \/>\n# SAK-30308 - Change the groupid and artifact id back<\/code><\/p>\n<p><code>git cherry-pick b6acdbee2bd9fd55f8a77de56732582a7eaa08ae<br \/>\n# Author: Charles Severance <csev@umich.edu><br \/>\n# Date:   Tue Feb 23 16:17:14 2016 -0500<br \/>\n# SAK-30362 - Fix small issues.<\/code><\/p>\n<p><code><br \/>\n...<br \/>\n<\/code><\/p>\n<p>Again &#8211; the script is the commits in reverse order so you are cherry-picking from oldest to newest.  I leave the commit details in as comment for my own sanity.<\/p>\n<p>I like the script in case you need to run this more than once.<\/p>\n<p>Hope this helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I finally figured out how to pull a sequence of commits from one branch to another using git&#8217;s cherry-pick feature. In Sakai, when we are preparing for a release, we make a release branch for the release (11.x) and then continue to move master forward and cherry-pick from master back to the release branch. We [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4942","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4942","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/comments?post=4942"}],"version-history":[{"count":4,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4942\/revisions"}],"predecessor-version":[{"id":4946,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/posts\/4942\/revisions\/4946"}],"wp:attachment":[{"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/media?parent=4942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/categories?post=4942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dr-chuck.com\/csev-blog\/wp-json\/wp\/v2\/tags?post=4942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}