0

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
Atihska
  • 4,803
  • 10
  • 56
  • 98
  • I think you need to correct what you mean.... or your understanding of merging. If you **merge** commit_id 3, that will _also_ carry changes from commits 2 and 1 into the branch that you are working on. So the question is not correctly worked if what you mean is to carry over the changes introduced by those 2 revisions (and then you would be cherry-picking). – eftshift0 Nov 05 '20 at 18:46
  • Given that those two revisions are _merge_ revisions (that's why git is complaining) you might consider to actually cherry-pick the real revisions instead of the merges into master? – eftshift0 Nov 05 '20 at 18:49
  • @eftshift0 Sorry for the confusion. Please see my updates. – Atihska Nov 05 '20 at 19:02
  • @eftshift0 Could you please provide me example on how to cherry pick the real revisions? Do you mean to cherry pick the parent commits? – Atihska Nov 05 '20 at 19:18
  • Provided it as an answer – eftshift0 Nov 05 '20 at 19:22
  • https://stackoverflow.com/questions/43846215/git-merge-three-way-git-merge could be helpful – ppuschmann Nov 05 '20 at 20:29

1 Answers1

1

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.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • What is `temp` here? And which id is `commit_id_3^2` referring to? Also what's `..` after `)`? – Atihska Nov 05 '20 at 19:34
  • Use whatever the commit id for the merge of the pr. For example `456785678^2` – eftshift0 Nov 05 '20 at 19:41
  • The .. is to be used _just like that_, no spaces between the closing `)` and the `..` and the following revision provided in the example. – eftshift0 Nov 05 '20 at 19:43
  • I am getting ```-sh: syntax error near unexpected token `('``` when I use the above cherry-pick. ```$ git checkout -b temp feature Switched to a new branch 'temp' $ git cherry-pick ( git merge-base e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f~ e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f^2 )..e6a35ad0b2363932ac190ec602a7fd0c8bf9f04f^2``` – Atihska Nov 05 '20 at 20:00
  • 1
    My bad. Let me correct it. (Look for the missing `$`) – eftshift0 Nov 05 '20 at 20:17
  • Thanks that worked. However, why are you doing on temp and then checking out to dev? The changes of cherry picking on temp gets lost once checked out to dev. Shouldn't we be doing cherry picking on dev itself as we are doing from master to dev? – Atihska Nov 05 '20 at 20:22
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224168/discussion-between-atihska-and-eftshift0). – Atihska Nov 05 '20 at 20:25
  • 1
    Well... that is just so that you can create a merge into dev... feel free to work on dev directly. – eftshift0 Nov 05 '20 at 20:28
  • @eftshift01 How can I revert the above changes if I already pushed to remote? As if I do `git revert --no-commit HEAD~3..HEAD` I get `error: commit fb690eaec7938abbd614b0b07a5364998c09f7a5 is a merge but no -m option was given.` – Atihska Nov 05 '20 at 22:08