简体   繁体   中英

Cherry-pick only certain commits from a branch

I am working on a repo that looks like this:

A-B <--(master)
   \
    C-D-E-F <--(features)

However, the owner would like me to split my commits into separate branches, like this:

A-B
   \
    +-C   <--(Feature-A)
    +-D-F <--(Feature-B)
    +-E   <--(Feature-C)

I feel like this should be a text-book cherry-pick, but I can't figure it out. This is further complicated by the fact I've already pushed the CDEF (features) branch up to my clone of the repo.

I tried doing

git rebase --onto B E

but it is not giving me the expected results.

There is no way to easily do this that I know of, but fairly simple (C, D and E are revision of C, D and E in your illiustration):

git branch Feature-A C
git checkout -b Feature-B master
git cherry-pick D
git cherry-pick features
git checkout -b Feature-C master
git cherry-pick E
git branch -D features
git branch FeatureA B
git checkout FeatureA
git cherry-pick C

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