views:

24

answers:

1

I've got a project which has a master branch and a stable branch - the branches diverged long time ago. Now I've got a couple commits on the stable branch, which I also want to have on the master branch (a bug fix). I cannot merge, as the branches diverged and there's loads of unmerged changes - I just want the 4 commits.

So I tried cherry-pick. However this fails since the top-level modules names changed from "project-module" scheme to "module". When cherry-picking, GIT creates the new files in the old directories (as on the old branch): the rename isn't detected. That's possibly because I get this warning:

warning: too many files (created: 278 deleted: 5364), skipping inexact rename detection

I tried git format-patch + git am, but this again creates the files in the old directories.

How can I apply the commits to the master branch?

Thanks, Adam

+1  A: 

I suspect you could make it work (but take a long time) by changing the value of merge.renameLimit:

merge.renameLimit

The number of files to consider when performing rename detection during a merge; if not specified, defaults to the value of diff.renameLimit.

I'm fairly certain cherry-pick will respect that value as well. If it doesn't, you could find a common ancestor of the two branches, apply the commits there, and then merge them into both branches, to make sure it's using the merge machinery. (Note that this is actually what I'd recommend doing in the first place. Merges are very much preferable to cherry-picks, because they don't create duplicate commits, and they preserve the flow of history.)

Jefromi
I stopped getting the error, but cherry-pick still creates the directory as it was in the old branch, instead of patching the files in the new branch.I think I'd need a way to apply some commits, doing some path translation ... any other way than git format-patch + the old UNIX patch -n?Thanks for the tip with the common ancestor, I'll try it next time. Though here I was merging a pull request, so I didn't have much control on what was the parent ...
adamw
Hmmm, yeah, I might fall back to "manual" (i.e. `sed`) patch editing. You should still use `git apply` though, instead of `patch`. It supports all the little extensions git makes to the patch format.
Jefromi
@adamw: I did just notice a commit in git.git: [merge-recursive: option to specify rename threshold](http://git.kernel.org/?p=git/git.git;a=commit;h=10ae7526bebb505ddddba01f76ec97d5f7b5e0e5) - it's possible your files aren't quite within the threshold, and you could get it to work the way you want by making it more lenient. (Assuming you haven't already just done it manually.)
Jefromi