简体   繁体   中英

Git cherry-pick range

How can I cherry-pick commit C4 and C5 ?

GitTree

I've tried git cherry-pick C4..C5 but I only get C4 . I think I don't really understand how this range thing works.

TL;DR version: C4^..C5

Unless a command treats it specially (and git cherry-pick does not), a range expression means "take all commits identified/findable by the right-side name, minus all commits identified/findable by the left-side name". In this case C5 identifies commits 0 through 5 inclusive, and C4 identifies 0 through 4 inclusive. Subtracting the second set of commits from the first set leaves you with just C5 .

Another way to look at it is that if the commits are related, you get a "half open interval", in the same way that the integers in (3, 7] are 4 5 6 7 .

As with the half-open integer interval, the usual easy trick is to start from one step back. Since the (first) parent of C4 is C4^ , C4^..C5 does the trick, just as (2, 7] would get you 3 4 5 6 7 .

(This fails if there's no parent, ie, the left side is the root commit. In that case you need some alternative strategy. Some commands make this easier, some make it harder, but for now we can just ignore the problem. :-) )

In this specific case, you don't need to use a range.

Example from man git-cherry-pick :

 git cherry-pick master~4 master~2
           Apply the changes introduced by the fifth and third last commits pointed to by master and create 2 new commits with these changes.

So for you:

git cherry-pick C4 C5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM