31

I have 33 commits in the main branch that are meshed up. Now I need to maintain the record neatly. So now I have created feature branches and I'm trying to classify those 33 commits in different feature branches. So can it be possible to pick multiple commits at a time to copy in the relevant feature branch? And I am also facing its conflicts when I tried multiple commits with the cherry-pick command.

git cherry-pick A B C

here A, B, C are the commits' hashcode.

DarkAjax
  • 15,175
  • 11
  • 52
  • 65
Nitu Dhaka
  • 1,190
  • 2
  • 13
  • 27

2 Answers2

21

You do it correct. The synopsis is

git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff] <commit>...

git cherry-pick goes from left to right commit. You can order how you want. If you have a conflict you have three choices. you can git cherry-pick --quit (stop cherry-picking and let your tree in his current state), git cherry-pick --abort (stop cherry-picking and reset your branch to the state where he was before you start git cherry-pick) or resolve this conflict with an editor or with git mergetool and then git cherry-pick --continue go to next commit in your list.

silvio
  • 1,867
  • 16
  • 34
  • 2
    +1 for mentioning `git cherry-pick --continue` for handling conflicts when cherry-picking multiple commits :) – JK ABC Mar 17 '16 at 06:31
6

If you need to maintain the record neatly you are better off with creating a topic branch and running git rebase -i <commit before the 33rd>, an interactive rebase. Follow the instructions for dropping commits. This should be simpler than cherry-picking so many commits in a particular strict order.

mockinterface
  • 13,017
  • 4
  • 25
  • 45
  • Ideally interactive rebase should occur in your feature branch, rewriting history in a develop or master branch mush handle with care – Asanka Siriwardena Feb 03 '17 at 10:52
  • Ideally, store the list the of commits, sort them into the different branches, then load the respective list for the interactive rebase from the file. That way you avoid the situation where you don't know whether a specific commit has already been taken care of. – cmaster - reinstate monica Sep 22 '20 at 09:51