简体   繁体   中英

How to merge 2 pull requests from one branch to another in git

I have 2 branches, say master and feature.

Here is the actual git log of the master branch of which I need 2 pull requests (#174 and #173) to be merged into my feature branch.

commit e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f (HEAD -> master, origin/master, origin/HEAD)
Merge: a922cb0 f45db00
Author: xyz
Date:   Wed Sep 2 17:55:32 2020 -0700

    Merge pull request #174 from xyz/v4upgrade
    
    readjust null values for string data type from v4

commit f45db00e1e4b1cce05eb1035b6bd3d3eab97f3bc
Author: xyz
Date:   Wed Sep 2 17:32:07 2020 -0700

    readjust null values for string data type from v4

commit a922cb0a5eb4bf2b7734af8041fb9cffcd2cee5f
Merge: 5f00c71 c9ab5c3
Author: xyz
Date:   Tue Sep 1 23:42:48 2020 -0700

    Merge pull request #173 from xyz/v4upgrade
    
    Implementation for UI fields for user info API

I want to merge pull request #173 and pull request #174 to feature branch.

I tried cherry picking commits but getting errors as follows:

git checkout feature
git cherry-pick e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f
error: commit e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f is a merge but no -m option was given.
fatal: cherry-pick failed

git cherry-pick a922cb0a5eb4bf2b7734af8041fb9cffcd2cee5f
error: commit a922cb0a5eb4bf2b7734af8041fb9cffcd2cee5f is a merge but no -m option was given.
fatal: cherry-pick failed

If you want to merge the changes that were coming from 2 PRs into another branch, then cherry-pick the revisions related to the PRs (independently) from master onto develop.

Say.... something like this:

git checkout -b temp dev # will work on temp to cherry-pick revisions
# cherry-pick changes related to commit_id_3
git cherry-pick $( git merge-base commit_id_3~ commit_id_3^2 )..commit_id_3^2
git checkout dev
git merge --no-ff -m "Merging changes from commit 3" temp # then we merge into dev

Same thing can be done for commit_1 as well. That is, assuming that those PRs are straight and there are no merges in their history.

Clarification: the merge-base allows to know from what revision the PR that was merged in commit_id_3 (or whatever) was started so that cherry-pick can only carry the revisions for development of whatever PR.

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