{"thread":{"id":"53212","subject":"Cherry pick a commit but with files in another location","startedAt":"2020-04-11T11:21:55Z","lastAt":"2020-04-13T05:43:52Z","messageCount":5,"participants":["Ani Sinha","Martin Ågren"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"395272","messageId":"FC3905FB-D3B9-433D-876D-8DB68D3491C3@anirban.org","threadId":"53212","inReplyTo":null,"subject":"Cherry pick a commit but with files in another location","fromName":"Ani Sinha","fromEmail":"ani@anirban.org","sentAt":"2020-04-11T11:21:42Z","receivedAt":"2020-04-11T11:21:55Z","isPatch":false,"sender":{"key":"ani@anirban.org","avatar":null},"body":"Hi,\n\nI have an use case where I need to cherry pick a change from one branch to another. The change will apply cleanly but the files in the branch  where I want to cherry pick the co mit to have been moved under a different directory. So simple cherry pick will result in conflicts. Is there a clean way to cherry pick in this case? Is there an option to provide -p0, -p1 etc to the patch?\n\nThanks\nAni "},{"id":"395274","messageId":"CAN0heSrFFABmtitJHu1tVw03oRCs63=UiSknmoZr60NT9dR9Fg@mail.gmail.com","threadId":"53212","inReplyTo":"FC3905FB-D3B9-433D-876D-8DB68D3491C3@anirban.org","subject":"Re: Cherry pick a commit but with files in another location","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-04-11T12:21:11Z","receivedAt":"2020-04-11T12:22:23Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Hi Ani,\n\nOn Sat, 11 Apr 2020 at 13:33, Ani Sinha <ani@anirban.org> wrote:\n>\n> I have an use case where I need to cherry pick a change from one branch\n> to another. The change will apply cleanly but the files in the branch\n> where I want to cherry pick the co mit to have been moved under a\n> different directory. So simple cherry pick will result in conflicts. Is\n> there a clean way to cherry pick in this case? Is there an option to\n> provide -p0, -p1 etc to the patch?\n\nI just tried the following commands. Admittedly, this example is a bit\nsilly, but at least for me, Git does handle the move just fine. Does\nthis work for you?\n\n  mkdir test\n  cd test\n  git init\n  mkdir olddir\n  echo old >olddir/file\n  git add olddir/\n  git commit -m Initial\n  git mv olddir newdir\n  git commit -m Move\n  echo new >newdir/file\n  git commit newdir/file -m Change\n  git checkout -b my-branch HEAD~2 # pre-move\n  git cherry-pick master\n  cat olddir/file\n\nWhat kind of conflicts do you get in your real-world use case?\n\nMartin\n"},{"id":"395275","messageId":"CAN0heSodSeT=Sj4pnutFPgbu9jjwQ_JBtBee1iyP=D3Oc_5G=g@mail.gmail.com","threadId":"53212","inReplyTo":"b26f041f-82d5-450f-998d-5a5c557a7994@Spark","subject":"Re: Cherry pick a commit but with files in another location","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-04-11T12:42:52Z","receivedAt":"2020-04-11T12:43:06Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Hi,\n\nOn Sat, 11 Apr 2020 at 14:24, Ani Sinha <ani@anirban.org> wrote:\n> On Apr 11, 2020, 17:51 +0530, Martin Ågren <martin.agren@gmail.com>, wrote:\n>\n> > On Sat, 11 Apr 2020 at 13:33, Ani Sinha <ani@anirban.org> wrote:\n>\n> > > I have an use case where I need to cherry pick a change from one branch\n> > > to another. The change will apply cleanly but the files in the branch\n> > > where I want to cherry pick the co mit to have been moved under a\n> > > different directory. So simple cherry pick will result in conflicts. Is\n> > > there a clean way to cherry pick in this case? Is there an option to\n> > > provide -p0, -p1 etc to the patch?\n>\n>\n> > I just tried the following commands. Admittedly, this example is a bit\n> > silly, but at least for me, Git does handle the move just fine. Does\n> > this work for you?\n> >\n> > mkdir test\n> > cd test\n> > git init\n> > mkdir olddir\n...\n> > git mv olddir newdir\n...\n\n> > What kind of conflicts do you get in your real-world use case?\n\n> My usecase is slightly different. The files I want to patch has been\n> moved under a new subdirectory which is under the original root\n> directory. So in order to patch, I need to add a new prefix to the patch\n> manually.\n\nI'm not able to fully guess your situation from this, but I wonder about\none thing: Do you use \"git cherry-pick\", \"git am\" or \"git apply\"? (Or\nsomething else entirely?) Are you aware of \"-p<n>\" for \"git apply\"\n(and \"--directory=<root>\"?) and are wondering what similar options are\navailable with \"git cherry-pick\"?\n\nI still don't fully understand what you're doing and what you're seeing,\nso it's hard to get a good picture of the problem.\n\nI'm about to leave, so if I stay silent for several hours, that's why. :)\n\nMartin\n"},{"id":"395277","messageId":"AE1E8050-EF04-47A0-96E0-27EEC4A0C013@anirban.org","threadId":"53212","inReplyTo":"CAN0heSodSeT=Sj4pnutFPgbu9jjwQ_JBtBee1iyP=D3Oc_5G=g@mail.gmail.com","subject":"Re: Cherry pick a commit but with files in another location","fromName":"Ani Sinha","fromEmail":"ani@anirban.org","sentAt":"2020-04-11T13:25:06Z","receivedAt":"2020-04-11T13:25:12Z","isPatch":false,"sender":{"key":"ani@anirban.org","avatar":null},"body":"\n\n> On Apr 11, 2020, at 6:13 PM, Martin Ågren <martin.agren@gmail.com> wrote:\n> \n> Do you use \"git cherry-pick\", \"git am\" or \"git apply\"?\n\nYes\n\n\n> (Or\n> something else entirely?) Are you aware of \"-p<n>\" for \"git apply\"\n> (and \"--directory=<root>\"?) and are wondering what similar options are\n> available with \"git cherry-pick\"?\nYes was wondering if similar options exist for cherry pick. I wanted to use cherry-pick  so that cherry picks can be tracked by git."},{"id":"395318","messageId":"CAN0heSp+Lmyx=eGjjioCYc6dmncz4Dcwo-MCsfMMKbP6vKdOzQ@mail.gmail.com","threadId":"53212","inReplyTo":"AE1E8050-EF04-47A0-96E0-27EEC4A0C013@anirban.org","subject":"Re: Cherry pick a commit but with files in another location","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2020-04-13T05:43:35Z","receivedAt":"2020-04-13T05:43:52Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"On Sat, 11 Apr 2020 at 15:25, Ani Sinha <ani@anirban.org> wrote:\n>\n> > On Apr 11, 2020, at 6:13 PM, Martin Ågren <martin.agren@gmail.com> wrote:\n> >\n> > Do you use \"git cherry-pick\", \"git am\" or \"git apply\"?\n>\n> Yes\n\nI still don't understand exactly what it is you're doing.\n\n> > (Or\n> > something else entirely?) Are you aware of \"-p<n>\" for \"git apply\"\n> > (and \"--directory=<root>\"?) and are wondering what similar options are\n> > available with \"git cherry-pick\"?\n>\n> Yes was wondering if similar options exist for cherry pick. I wanted\n> to use cherry-pick  so that cherry picks can be tracked by git.\n\nAre you working on some repo that is publicly available, e.g., on\ngithub/gitlab? If so, you could post a link.\n\nWhat is it that you try doing? You could post the commands you execute.\n\nWhat happens? You could post error messages.\n\nWhat do you expect *should* happen? You could try to describe your\nexpectations.\n\nWithout that kind of information, it is unfortunately hard to help you.\n\nOne final thought: Have you actually tried cherry-picking the way you\nwant to, and have you actually encountered a problem? Or are you looking\nfor solutions to a problem that you're not sure you're having?\n\nMartin\n"}]}