gcbenison
gcbenison

Reputation: 11963

Cherry-pick this commit - but apply the patch to a differently-named file

Initially there was branchA:fileA. Then in branchB, fileA split into two components, fileA and fileB. Then in branchA, fileA was edited. I want to cherry-pick this change into branchB; the thing is, in that branch, the patch should be applied to fileB, not fileA, and git does not seem to be able to figure this out via a straightforward git cherry-pick <sha1> from branchB.

The commit I want to cherry pick touches only fileA. Is there a way I can coerce git into applying it to fileB?

I believe this situation is common enough - picture a class hierarchy adding another layer in branchB, for example.

Upvotes: 1

Views: 75

Answers (1)

gcbenison
gcbenison

Reputation: 11963

Well, this works, but I still wonder if there is a more idiomatic way -

git show -c <sha1> | patch <path to fileB>
git add <path to fileB>
git commit -C <sha1>

Upvotes: 2

Related Questions