Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cherry-pick Commit from a different repo

I was trying to cherrypick this commits

  • https://github.com/AICP/frameworks_base/commit/59ebfb7146616e57c15469d7ea85c4362c2fab3c
  • https://github.com/AICP/frameworks_base/commit/e24d0c250b4f80618f4b6064ad21d9c913890899

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?

like image 691
Gopinaidu Avatar asked Jan 01 '17 04:01

Gopinaidu


People also ask

Can I cherry pick commits from another repo?

It is possible to cherry pick from another repo using the command line. You will first need to add the other repository as a remote and then fetch the changes. From there, you should be able to see the commit in your repo and cherry pick it.

How do you take a commit from one repo to another?

In order to get commits from the other repository, You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it.

How do you cherry pick a commit from another branch Devops?

Open up Team Explorer and check out the branch you want to cherry-pick changes into using the Branches view. Right-click the branch containing the changes you want and select View History.... Right-click the commit you want to cherry-pick and select Cherry-pick.

Can I cherry pick merge commit?

You can use the GitLab UI to cherry-pick single commits or entire merge requests. You can even cherry-pick a commit from a fork of your project. Support for tracking commits cherry-picked from the command line is tracked in this issue.


2 Answers

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
like image 91
VonC Avatar answered Sep 21 '22 01:09

VonC


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
like image 32
Saurav Sahu Avatar answered Sep 22 '22 01:09

Saurav Sahu