Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git cherry pick - range of commits and exclude some in between

I normally use the following git command to cherryppick a range of gerrits..no how do I exclude a couple gerrits in between.. can the below command be modified or is there one where we can pick a range of gerrits and exclude the ones we want..

git cherrypick fromgerritSHA1..togerritSHA1 
like image 665
carte blanche Avatar asked Mar 28 '13 16:03

carte blanche


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.

How do you cherry pick few commits?

The easiest way to cherry-pick a commit is to use the “cherry-pick” command with the commit hash. In order to cherry-pick changes, you will need to identify your commit hashes.


1 Answers

You can specify multiple ranges:

git cherry-pick A..B C..D E..F 

or even specific commits:

git cherry-pick A B C D E F 

If you have lots of commits you want to exclude, it might be easier to do something like this (sort of like a poor man's git rebase -i for git cherry-pick):

git log --pretty=oneline A..F | tac > tempfile.txt < edit tempfile.txt to remove the commits you don't want > git cherry-pick $(awk '{print $1}' tempfile.txt) 

Edit: Added recommendation to tac the log, since git cherry-pick wants to see the commits in the opposite order from what git log produces (could also use git log --reverse ...).

like image 70
twalberg Avatar answered Oct 12 '22 03:10

twalberg