# Cherry pick a commit but with files in another location

5 messages from 2020-04-11 to 2020-04-13. Participants: Ani Sinha, Martin Ågren.
Thread: https://gitlist.dev/t/53212

## Ani Sinha, 2020-04-11 11:21

Subject: Cherry pick a commit but with files in another location
Message-ID: <FC3905FB-D3B9-433D-876D-8DB68D3491C3@anirban.org>
URL: https://gitlist.dev/e/FC3905FB-D3B9-433D-876D-8DB68D3491C3%40anirban.org

```
Hi,

I 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?

Thanks
Ani 
```

## Martin Ågren, 2020-04-11 12:21

Subject: Re: Cherry pick a commit but with files in another location
Message-ID: <CAN0heSrFFABmtitJHu1tVw03oRCs63=UiSknmoZr60NT9dR9Fg@mail.gmail.com>
URL: https://gitlist.dev/e/CAN0heSrFFABmtitJHu1tVw03oRCs63%3DUiSknmoZr60NT9dR9Fg%40mail.gmail.com
In-Reply-To: <FC3905FB-D3B9-433D-876D-8DB68D3491C3@anirban.org>

```
Hi Ani,

On Sat, 11 Apr 2020 at 13:33, Ani Sinha <ani@anirban.org> wrote:
>
> I 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?

I just tried the following commands. Admittedly, this example is a bit
silly, but at least for me, Git does handle the move just fine. Does
this work for you?

  mkdir test
  cd test
  git init
  mkdir olddir
  echo old >olddir/file
  git add olddir/
  git commit -m Initial
  git mv olddir newdir
  git commit -m Move
  echo new >newdir/file
  git commit newdir/file -m Change
  git checkout -b my-branch HEAD~2 # pre-move
  git cherry-pick master
  cat olddir/file

What kind of conflicts do you get in your real-world use case?

Martin

```

## Martin Ågren, 2020-04-11 12:42

Subject: Re: Cherry pick a commit but with files in another location
Message-ID: <CAN0heSodSeT=Sj4pnutFPgbu9jjwQ_JBtBee1iyP=D3Oc_5G=g@mail.gmail.com>
URL: https://gitlist.dev/e/CAN0heSodSeT%3DSj4pnutFPgbu9jjwQ_JBtBee1iyP%3DD3Oc_5G%3Dg%40mail.gmail.com
In-Reply-To: <b26f041f-82d5-450f-998d-5a5c557a7994@Spark>

```
Hi,

On Sat, 11 Apr 2020 at 14:24, Ani Sinha <ani@anirban.org> wrote:
> On Apr 11, 2020, 17:51 +0530, Martin Ågren <martin.agren@gmail.com>, wrote:
>
> > On Sat, 11 Apr 2020 at 13:33, Ani Sinha <ani@anirban.org> wrote:
>
> > > I 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?
>
>
> > I just tried the following commands. Admittedly, this example is a bit
> > silly, but at least for me, Git does handle the move just fine. Does
> > this work for you?
> >
> > mkdir test
> > cd test
> > git init
> > mkdir olddir
...
> > git mv olddir newdir
...

> > What kind of conflicts do you get in your real-world use case?

> My usecase is slightly different. The files I want to patch has been
> moved under a new subdirectory which is under the original root
> directory. So in order to patch, I need to add a new prefix to the patch
> manually.

I'm not able to fully guess your situation from this, but I wonder about
one thing: Do you use "git cherry-pick", "git am" or "git apply"? (Or
something else entirely?) Are you aware of "-p<n>" for "git apply"
(and "--directory=<root>"?) and are wondering what similar options are
available with "git cherry-pick"?

I still don't fully understand what you're doing and what you're seeing,
so it's hard to get a good picture of the problem.

I'm about to leave, so if I stay silent for several hours, that's why. :)

Martin

```

## Ani Sinha, 2020-04-11 13:25

Subject: Re: Cherry pick a commit but with files in another location
Message-ID: <AE1E8050-EF04-47A0-96E0-27EEC4A0C013@anirban.org>
URL: https://gitlist.dev/e/AE1E8050-EF04-47A0-96E0-27EEC4A0C013%40anirban.org
In-Reply-To: <CAN0heSodSeT=Sj4pnutFPgbu9jjwQ_JBtBee1iyP=D3Oc_5G=g@mail.gmail.com>

```


> On Apr 11, 2020, at 6:13 PM, Martin Ågren <martin.agren@gmail.com> wrote:
> 
> Do you use "git cherry-pick", "git am" or "git apply"?

Yes


> (Or
> something else entirely?) Are you aware of "-p<n>" for "git apply"
> (and "--directory=<root>"?) and are wondering what similar options are
> available with "git cherry-pick"?
Yes was wondering if similar options exist for cherry pick. I wanted to use cherry-pick  so that cherry picks can be tracked by git.
```

## Martin Ågren, 2020-04-13 05:43

Subject: Re: Cherry pick a commit but with files in another location
Message-ID: <CAN0heSp+Lmyx=eGjjioCYc6dmncz4Dcwo-MCsfMMKbP6vKdOzQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAN0heSp%2BLmyx%3DeGjjioCYc6dmncz4Dcwo-MCsfMMKbP6vKdOzQ%40mail.gmail.com
In-Reply-To: <AE1E8050-EF04-47A0-96E0-27EEC4A0C013@anirban.org>

```
On Sat, 11 Apr 2020 at 15:25, Ani Sinha <ani@anirban.org> wrote:
>
> > On Apr 11, 2020, at 6:13 PM, Martin Ågren <martin.agren@gmail.com> wrote:
> >
> > Do you use "git cherry-pick", "git am" or "git apply"?
>
> Yes

I still don't understand exactly what it is you're doing.

> > (Or
> > something else entirely?) Are you aware of "-p<n>" for "git apply"
> > (and "--directory=<root>"?) and are wondering what similar options are
> > available with "git cherry-pick"?
>
> Yes was wondering if similar options exist for cherry pick. I wanted
> to use cherry-pick  so that cherry picks can be tracked by git.

Are you working on some repo that is publicly available, e.g., on
github/gitlab? If so, you could post a link.

What is it that you try doing? You could post the commands you execute.

What happens? You could post error messages.

What do you expect *should* happen? You could try to describe your
expectations.

Without that kind of information, it is unfortunately hard to help you.

One final thought: Have you actually tried cherry-picking the way you
want to, and have you actually encountered a problem? Or are you looking
for solutions to a problem that you're not sure you're having?

Martin

```
