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

后端 未结 3 707
深忆病人
深忆病人 2020-12-24 13:34

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 o

3条回答
  •  遥遥无期
    2020-12-24 13:57

    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 ...).

提交回复
热议问题