Cherry-pick Commit from a different repo

14.8k views Asked by At

I was trying to cherrypick this commits

from https://github(dot)com/AICP/frameworks_base/ to https:// github(dot)com/Gopinaidu7/android_frameworks_base

I created a new branch with name master and switched to it.
I then did:

git cherry-pick 59ebfb7

and it got

fatal: bad revision '59ebfb7'

I also tried:

git cherry-pick 59ebfb7146616e57c15469d7ea85c4362c2fab3c 

and got this error

fatal: bad object 59ebfb7146616e57c15469d7ea85c4362c2fab3c.

I was doing wrong and did tried to pick those commits since last night.
I was not able to do it, can someone point me with correct commands in sequence?

3

There are 3 answers

8
VonC On BEST ANSWER

You need to add that other repo as a remote first:

 git clone  https://github.com/Gopinaidu7/android_frameworks_base
 cd android_frameworks_base
 git remote add other https://github.com/AICP/frameworks_base

Then fetch:

 git fetch other

Now you can cherry-pick using the SHA1. And then push.

If the cherry-picked commit is a merged commit:

git cherry-pick -m 1 59ebfb7
0
krishna chaitanya On

'bad revision' message comes whenever you are trying to cherry-pick a commit and you don't have that remote branch locally.

Solution

git fetch origin <remote_committed_branch>
git cherry-pick <commit-id>
1
Saurav Sahu On

You don't need to create a new branch, just clone the target branch as suggested by @Vonc, and then run this command:

git checkout target_branch
git fetch https://github.com/AICP/frameworks_base && git cherry-pick 59ebfb7