1

Assuming I have two repositories called repositoryA and repositoryB. I need to merge a commit abcdefgh which is in a branch in repositoryA and called branchA to another branch called branchB and located in repositoryB.

in repositoryB:

git checkout -b branchB
git remote add repositoryA git@github.com:xxx/repositoryA.git
git remote update
git cherry-pick abcdefgh

This doesn't work, when I merge, it merges the entire branchA to branchB and makes a lot of conflicts and cherry-pick and above it fails.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34

1 Answers1

1

The first two steps as you mentioned are good! But then instead of

git remote update

do

git fetch repositoryA branchA

and then you can cherry pick

git cherry-pick abcdefgh
caramba
  • 21,963
  • 19
  • 86
  • 127
  • Thanks for your answer. But I get this error `error: commit abcdefgh is a merge but no -m option was given.` – schedulingqs Jan 02 '22 at 17:17
  • @schedulingqs inside `branchA` from `repositoryA` can you do `git log` and then take the commit hash. Then try to `git cherry-pick [commit-hash]` which will look something like `git cherry-pick a4ab52a` – caramba Jan 02 '22 at 17:22
  • @schedulingqs see also: https://stackoverflow.com/a/9229393/2008111 (looks like you are not trying to cherry-pick a single commit but a merge-commit) – caramba Jan 02 '22 at 17:24
  • `git remote update` runs `git fetch` on *all* remotes by default (same as `git fetch --all`), so that doesn't explain anything. I think the OP must have run `git merge abcdefgh` instead of `git cherry-pick abcdefgh` originally. – torek Jan 02 '22 at 17:37