{"thread":{"id":"22325","subject":"cherry picking several patches at once","startedAt":"2010-01-21T16:11:57Z","lastAt":"2010-01-24T15:31:43Z","messageCount":7,"participants":["Felipe Balbi","Felipe Contreras","Marc Weber","Sverre Rabbelier"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"132309","messageId":"20100121161157.GA3628@gandalf","threadId":"22325","inReplyTo":null,"subject":"cherry picking several patches at once","fromName":"Felipe Balbi","fromEmail":"me@felipebalbi.com","sentAt":"2010-01-21T16:11:57Z","receivedAt":"2010-01-21T16:11:57Z","isPatch":false,"sender":{"key":"me@felipebalbi.com","avatar":null},"body":"Hi,\n\nI wonder if it's possible to cherry several patches at once ?\nCan't find anything on any docs, but something like:\n\n$ git cherry-pick <commit_id_start>..<commit_id_end> -- \\\n\t/path/to/directory\n\nI want to do that because I keep patches to the musb driver (on linux\nkernel) based on top of linus' mainline tree and on top of internal\ntree.\n\nThe internal tree is outdated (not following mainline), but the musb\ndriver is basically in sync, so cherry picking works, but it's a bit\npainful when I have to pick patches from community and manually\ncherry-pick to the other branch based on my internal tree.\n\nIf there's a way (besides git rebase --onto) to do that I would very\nmuch like to know.\n\nAnother thing that would be nice to have, is to pass the HEAD to which\nwe want to cherry-pick, so we can cherry-pick to not-checked-out\nbranches. Something like:\n\n$ git cherry-pick <commit_id> <my_branch_name>\n\nand combining both, of course:\n\n$ git cherry-pick <commit_id_start>..<commit_id_end> \\\n\t<my_branch_name> -- /path/to/directory\n\n-- \nbalbi\n"},{"id":"132430","messageId":"94a0d4531001221557n7a892f03u5e5d1c5e5ba5fea0@mail.gmail.com","threadId":"22325","inReplyTo":"20100121161157.GA3628@gandalf","subject":"Re: cherry picking several patches at once","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2010-01-22T23:57:40Z","receivedAt":"2010-01-22T23:57:40Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Heippa,\n\nOn Thu, Jan 21, 2010 at 6:11 PM, Felipe Balbi <me@felipebalbi.com> wrote:\n> I wonder if it's possible to cherry several patches at once ?\n> Can't find anything on any docs, but something like:\n>\n> $ git cherry-pick <commit_id_start>..<commit_id_end> -- \\\n>        /path/to/directory\n>\n> I want to do that because I keep patches to the musb driver (on linux\n> kernel) based on top of linus' mainline tree and on top of internal\n> tree.\n>\n> The internal tree is outdated (not following mainline), but the musb\n> driver is basically in sync, so cherry picking works, but it's a bit\n> painful when I have to pick patches from community and manually\n> cherry-pick to the other branch based on my internal tree.\n>\n> If there's a way (besides git rebase --onto) to do that I would very\n> much like to know.\n\nHave you tried something like:\ngit format-patch old-base --full-diff -- /path\ngit am -3 *.patch\n\n> Another thing that would be nice to have, is to pass the HEAD to which\n> we want to cherry-pick, so we can cherry-pick to not-checked-out\n> branches.\n\nI think that would not be possible because of the challenges when\ndealing with conflicts.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"132437","messageId":"1264205767-sup-4547@nixos","threadId":"22325","inReplyTo":"94a0d4531001221557n7a892f03u5e5d1c5e5ba5fea0@mail.gmail.com","subject":"Re: cherry picking several patches at once","fromName":"Marc Weber","fromEmail":"marco-oweber@gmx.de","sentAt":"2010-01-23T00:24:06Z","receivedAt":"2010-01-23T00:24:06Z","isPatch":false,"sender":{"key":"marco-oweber@gmx.de","avatar":null},"body":"Hi,\n\nI like both ideas. I fact I had both my self.\nCherry-picking a range can be implemented using a simple shell script.\nSo that is not that important.\n\n> I think that would not be possible because of the challenges when\n> dealing with conflicts.\nIf cherry-picking to a not checkout branch causes conflicts it could be\nrejected. It's that simple.\n\nThe use case is: You have many topic-branches. Of course you develop on\nthe big temporary merge. However you want to push your changes to the\ntopic branches. You may be working on multiple topics at the same time.\nSome of the topics may quick hacks to make a porject work on your system\nsuch as patching shebang lines, change PHP require lines etc.\n\nCurrently you have to\ngit checkout topic1; git cherry-pick big-merge\ngit checkout topic2; git cherry-pick big-merge~2\ngit checkout big-merge\n\ncompare this to\n\ngit cherry-push HEAD    topic1\ngit cherry-push HEAD~2  topic2\n\nnot much typing.\n\nVery often there are no conflicts and you know that there are none.\n\nIf you have conflicts you can still fallback going the slow way.\nMaybe the command could behave this way:\n\ngit cherry-push-checkout-on-failure hash other-branch\n\nI'd be very happy about such a git cherry-push-checkout-on-failure\ncommand. I'm not sure whether the command should be renamed. I did so\nfor fun.\n\nMarc Weber\n"},{"id":"132476","messageId":"fabb9a1e1001230317x650b8f21y5ee3fa73e9ffea62@mail.gmail.com","threadId":"22325","inReplyTo":"1264205767-sup-4547@nixos","subject":"Re: cherry picking several patches at once","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-01-23T11:17:19Z","receivedAt":"2010-01-23T11:17:19Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jan 23, 2010 at 01:24, Marc Weber <marco-oweber@gmx.de> wrote:\n> git cherry-push-checkout-on-failure hash other-branch\n\nHeh, I could use that exact command myself, as I use the exact\nworkflow you described :).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"132532","messageId":"1264330354.14140.1.camel@gandalf","threadId":"22325","inReplyTo":"94a0d4531001221557n7a892f03u5e5d1c5e5ba5fea0@mail.gmail.com","subject":"Re: cherry picking several patches at once","fromName":"Felipe Balbi","fromEmail":"me@felipebalbi.com","sentAt":"2010-01-24T10:52:34Z","receivedAt":"2010-01-24T10:52:34Z","isPatch":false,"sender":{"key":"me@felipebalbi.com","avatar":null},"body":"Hi,\n\nOn Sat, 2010-01-23 at 01:57 +0200, Felipe Contreras wrote:\n> Have you tried something like:\n> git format-patch old-base --full-diff -- /path\n> git am -3 *.patch\n\nyes, sure that can be done, but the idea is to avoid having\nformat-patch, switch branches and git am those patches ;-)\n\n> I think that would not be possible because of the challenges when\n> dealing with conflicts.\n\nthere shouldn't be any. I have the same driver internally and publicly\nand would be cherry-picking only the patches for that particular driver.\n\n-- \nbalbi\n"},{"id":"132535","messageId":"94a0d4531001240510g25ea3398qdd0c7b98f9b81209@mail.gmail.com","threadId":"22325","inReplyTo":"1264330354.14140.1.camel@gandalf","subject":"Re: cherry picking several patches at once","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2010-01-24T13:10:09Z","receivedAt":"2010-01-24T13:10:09Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Jan 24, 2010 at 12:52 PM, Felipe Balbi <me@felipebalbi.com> wrote:\n> On Sat, 2010-01-23 at 01:57 +0200, Felipe Contreras wrote:\n>> Have you tried something like:\n>> git format-patch old-base --full-diff -- /path\n>> git am -3 *.patch\n>\n> yes, sure that can be done, but the idea is to avoid having\n> format-patch, switch branches and git am those patches ;-)\n\nWhen you do a 'git rebase' you are also doing a format-patch/am, but\nthat happens inside the script; you can write a script that does what\nyou want in a way that you wouldn't notice it: save the old branch,\ngit stash, switch to new branch, generate the patches, apply the\npatches, switch back to the old branch, git stash pop.\n\n>> I think that would not be possible because of the challenges when\n>> dealing with conflicts.\n>\n> there shouldn't be any. I have the same driver internally and publicly\n> and would be cherry-picking only the patches for that particular driver.\n\nOk, in that case we would just need a cherry-pick that can commit to a\nseparate branch, however I don't think git internals allow that kind\nof thing.\n\n-- \nFelipe Contreras\n"},{"id":"132543","messageId":"1264345006-sup-8582@nixos","threadId":"22325","inReplyTo":"94a0d4531001240510g25ea3398qdd0c7b98f9b81209@mail.gmail.com","subject":"Re: cherry picking several patches at once","fromName":"Marc Weber","fromEmail":"marco-oweber@gmx.de","sentAt":"2010-01-24T15:31:43Z","receivedAt":"2010-01-24T15:31:43Z","isPatch":false,"sender":{"key":"marco-oweber@gmx.de","avatar":null},"body":"> Ok, in that case we would just need a cherry-pick that can commit to a\n> separate branch, however I don't think git internals allow that kind\n> of thing.\n\nWhich is the best way to implement this git-cherry-push command?\n\n# naive implementation (BASH function):\n\ngitCherryPush(){\n  # start a subshell so that failures don't quit your shell because of\n  # set -e\n  (\n  set -e\n  local branch=$(cat .git/HEAD |  sed 's@ref: refs/heads/\\(.*\\)@\\1@')\n  local otherBranch=$1; shift\n  commits=\"$(\n    for range in \"$@\"; do\n      local HAS_DOTS=${range%%*..*}\n      # add -1 if commit is not a range\n      git rev-list --reverse ${HAS_DOTS:+-1} \"$range\"\n    done\n  )\"\n\n  echo \"checking out other branch\"\n  git checkout \"$otherBranch\"\n  echo \"$commits\" | while read c; do\n    git cherry-pick \"$c\" || {\n      echo \"cherry-picking $c failed. fix it, exit 1 to abort. Starting subshell now\"\n      $SHELL || [ \"$?\" != 1] || return\n    }\n  done\n  echo \"checking out original branch $branch\"\n  git checkout $branch\n  )\n}\n\nzsh completion:\n\ncompdef _gitCherryPush gitCherryPush\n_gitCherryPush(){\n  typeset -A opt_args\n  _arguments -S \\\n   ':branch to which to move commit range:__git_branch_names' \\\n   ':branch to which to move commit range:__git_commit_ranges2'\n}\n\nExample usage (push last 5 commits)\ngitCherryPush branch-to-push-to HEAD~4 HEAD~4..HEAD\n\nCan I checkout the other branch without touching the working copy? I\ndon't think so because cherry-pick will fail operating if working\ndirectory is not clean, correct?\n\nIs something like this worth comitting to the main repo?\n\nMarc Weber\n"}]}