Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When it comes to a range of commits, cherry-picking <del>is</del> <em>was</em> not practical.</p> <p>As <a href="https://stackoverflow.com/a/3664543/6309">mentioned below</a> by <a href="https://stackoverflow.com/users/442025/keith-kim">Keith Kim</a>, Git 1.7.2+ introduced the ability to cherry-pick a range of commits (but you still need to be aware of the <a href="https://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git/881112#881112">consequence of cherry-picking for future merge</a>)</p> <blockquote> <p>git cherry-pick" learned to pick a range of commits<br> (e.g. "<code>cherry-pick A..B</code>" and "<code>cherry-pick --stdin</code>"), so did "<code>git revert</code>"; these do not support the nicer sequencing control "<code>rebase [-i]</code>" has, though.</p> </blockquote> <p><a href="https://stackoverflow.com/users/42961/damian">damian</a> <a href="https://stackoverflow.com/a/3933416/6309">comments</a> and warns us:</p> <blockquote> <p>In the "<code>cherry-pick A..B</code>" form, <strong><code>A</code> should be older than <code>B</code></strong>.<br> <strong>If they're the wrong order the command will silently fail</strong>.</p> </blockquote> <p>If you want to pick the <strong>range <code>B</code> through <code>D</code> (inclusive)</strong> that would be <strong><code>B^..D</code></strong>.<br> See "<a href="https://stackoverflow.com/a/9853814/6309">Git create branch from range of previous commits?</a>" as an illustration.</p> <p>As <a href="https://stackoverflow.com/users/2541573/jubobs">Jubobs</a> mentions <a href="https://stackoverflow.com/questions/1994463/how-to-cherry-pick-a-range-of-commits-and-merge-into-another-branch/1994491#comment51629396_1994491">in the comments</a>: </p> <blockquote> <p>This assumes that <code>B</code> is not a root commit; you'll get an "<code>unknown revision</code>" error otherwise.</p> </blockquote> <p>Note: as of Git 2.9.x/2.10 (Q3 2016), you can cherry-pick a range of commit directly on an orphan branch (empty head): see "<a href="https://stackoverflow.com/a/38285663/6309">How to make existing branch an orphan in git</a>".</p> <hr> <p>Original answer (January 2010)</p> <p>A <code>rebase --onto</code> would be better, where you replay the given range of commit on top of your integration branch, as <a href="https://stackoverflow.com/questions/509859/what-is-the-best-way-to-git-patch-a-subrange-of-a-branch">Charles Bailey described here</a>.<br> (also, look for "Here is how you would transplant a topic branch based on one branch to another" in the <a href="http://git-scm.com/docs/git-rebase" rel="noreferrer">git rebase man page</a>, to see a practical example of <code>git rebase --onto</code>)</p> <p>If your current branch is integration:</p> <pre class="lang-sh prettyprint-override"><code># Checkout a new temporary branch at the current location git checkout -b tmp # Move the integration branch to the head of the new patchset git branch -f integration last_SHA-1_of_working_branch_range # Rebase the patchset onto tmp, the old location of integration git rebase --onto tmp first_SHA-1_of_working_branch_range~1 integration </code></pre> <p>That will replay everything between:</p> <ul> <li>after the parent of <code>first_SHA-1_of_working_branch_range</code> (hence the <code>~1</code>): the first commit you want to replay</li> <li>up to "<code>integration</code>" (which points to the last commit you want to replay, from the <code>working</code> branch)</li> </ul> <p>to "<code>tmp</code>" (which points to where <code>integration</code> was pointing before)</p> <p>If there is any conflict when one of those commits is replayed:</p> <ul> <li>either solve it and run "<code>git rebase --continue</code>". </li> <li>or skip this patch, and instead run "<code>git rebase --skip</code>"</li> <li>or cancel the all thing with a "<code>git rebase --abort</code>" (and put back the <code>integration</code> branch on the <code>tmp</code> branch)</li> </ul> <p>After that <code>rebase --onto</code>, <code>integration</code> will be back at the last commit of the integration branch (that is "<code>tmp</code>" branch + all the replayed commits)</p> <p>With cherry-picking or <code>rebase --onto</code>, do not forget it has consequences on subsequent merges, as <a href="https://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git/881112#881112">described here</a>.</p> <hr> <p>A pure "<code>cherry-pick</code>" solution is <a href="https://groups.google.com/d/msg/git-version-control/F0KYheOR2dY/pLj70x0A8L0J" rel="noreferrer">discussed here</a>, and would involve something like:</p> <blockquote> <p>If you want to use a patch approach then "git format-patch|git am" and "git cherry" are your options.<br> Currently, <code>git cherry-pick</code> accepts only a single commit, but if you want to pick the range <code>B</code> through <code>D</code> that would be <code>B^..D</code> in git lingo, so </p> </blockquote> <pre class="lang-sh prettyprint-override"><code>git rev-list --reverse --topo-order B^..D | while read rev do git cherry-pick $rev || break done </code></pre> <p>But anyway, when you need to "replay" a range of commits, the word "replay" should push you to use the "<code>rebase</code>" feature of Git.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload