git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Cherry pick a commit but with files in another location

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Apr 11, 2020, 12:21 UTC
Message-ID
<CAN0heSrFFABmtitJHu1tVw03oRCs63=UiSknmoZr60NT9dR9Fg@mail.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:
Show 7 quoted lines
>
> 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
Previous: Ani SinhaNext: Martin Ågren
Message 2 of 5 in “Cherry pick a commit but with files in another location”
  1. Ani SinhaApr 11, 2020
  2. Martin ÅgrenApr 11, 2020
  3. Martin ÅgrenApr 11, 2020
  4. Ani SinhaApr 11, 2020
  5. Martin ÅgrenApr 13, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.