简体   繁体   中英

Git merge/cherry-pick all commits of a branch

Scenario:

master
|
\
  dev
  |
  \
    feature1
    |
    |
    |
   /
  |
  /  
tagV1
  |
  \
    feature2
    |
    |
   /
  |
 /
tagV2
  |
  \
    fixForV1
    |
    |
   /
  |
  /  
tagV1_1

Description:

  1. Create repo
  2. Create and checkout branch dev
  3. Create and checkout branch feature1 .. implement the feature
  4. Checkout dev and merge feature1, delete feature1
  5. Checkout master merge dev
  6. Create tagV1 (Will be delivered to the customer)
  7. Checkout dev
  8. Create and checkout branch feature2 .. implement the feature
  9. Checkout dev and merge feature2, delete feature2
  10. Checkout master merge dev
  11. Create tagV2 (Will be delivered same or different customer)
  12. Checkout dev
  13. Create and checkout branch fixForV1 .. implement the fix
  14. Checkout dev and merge fixForV1
  15. ???

15… We need to merge tagV1 and the commits made on fixForV1 (Without including the commits made on feature2). After the merge we will create a new tag tagV1_1 and deliver this to the customer.

I know I can achieve this by doing a cherry-pick {hash of first commit made on fixForV1} ^..{hash of last commit made on fixForV1} Is there a better way to do this?

If I understand your requirements correctly, you can also work like this:

  1. git checkout fixForV1
  2. git format-patch tagV2 -- get all the patches from tagV2 to head of fixForV1
  3. git checkout -b branchV1 tagV1 -- create a new branch based on tagV1
  4. git apply *.patch -- apply patches we generated in step 1

If you are lucky, all patches apply without issue then you're done. If not lucky, apply the patches one by one in order then fix the conflicts accordingly.

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