Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cherry-Picking few commits from another branch

I have a scenario where I don't want to cherry-pick a specific commit but a range of git commits from remote. I can do force pull with hard option but that will get all the commits including latest changes from remote. Please suggest how can I pick range of commits from remote.


For instance, this is what I am trying:

git checkout -b newbranch 62ecb3  git rebase --onto master 76cada, 56qwqw, 46erer 
like image 491
Varun Maggo Avatar asked Sep 08 '17 05:09

Varun Maggo


People also ask

Can you cherry pick a range of commits?

The thing is if you are cherry picking a range of commits, it will cherry pick the parent commits correctly but then when it hits a normal commit, it fails and says commit is not a merge.

Can you 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.


2 Answers

Let's say the history is A-B-C-D-E-F-G, and you'd like to cherry-pick C-D-E-F.

git cherry-pick B..F 

or

git cherry-pick C^..F 

or

git cherry-pick C D E F 
like image 188
ElpieKay Avatar answered Oct 04 '22 23:10

ElpieKay


Use
git cherry-pick 76cada 56qwqw 46erer

like image 22
Dane Avatar answered Oct 04 '22 21:10

Dane