14

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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Gopinaidu
  • 143
  • 1
  • 1
  • 4
  • Can you explain what you mean by `i created a new branch with name master and switched to it`? Did you add a new remote for https://github.com/AICP/frameworks_base in your existing repository? – Guildencrantz Jan 01 '17 at 04:37

3 Answers3

20

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
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @Gopinaidu you used the old url ending with a slash (/). As I said, I edited the answer. Plus, you need to do so in another brand new empty folder: say `~/test`, and don't forget the `cd ~/test/android_frameworks_base` after the `git clone` part: you need to be in the cloned repo for the other git commands. – VonC Jan 01 '17 at 05:07
  • @Gopinaidu Look at http://stackoverflow.com/posts/41413383/revisions to see what I have removed – VonC Jan 01 '17 at 05:07
  • sorry , i forgot to change the directory and above comment is a mistake .. – Gopinaidu Jan 01 '17 at 05:13
  • Here is the error : gopinaidunani@gopinaidu:~/framework/android_frameworks_base$ git cherry-pick 59ebfb7146616e57c15469d7ea85c4362c2fab3c error: Commit 59ebfb7146616e57c15469d7ea85c4362c2fab3c is a merge but no -m option was given. fatal: cherry-pick failed gopinaidunani@gopinaidu:~/framework/android_frameworks_base$ – Gopinaidu Jan 01 '17 at 05:14
  • @Gopinaidu you should really try and cherry-pick a regular commit, not a merge commit. But if you must: `git cherry-pick -m 1 59ebfb7` – VonC Jan 01 '17 at 05:15
  • Thanks bro , u saved my day – Gopinaidu Jan 01 '17 at 06:05
  • @Gopinaidu You are most welcome. I have edited the answer to include the `-m 1` syntax for cherry-picking a merge commit. That will help others. – VonC Jan 01 '17 at 06:06
  • Yes , even that saved my time too .Thanks alot u solved my problem – Gopinaidu Jan 01 '17 at 14:07
1

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
Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
  • 1
    this should be the answer to be found everywhere to cherry-pick without having to add a remote. So useful!! Locally, I do `git fetch /another_build_dir/ && git cherry-pick ` – QbProg Oct 25 '21 at 15:03
0

'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>