How to apply a patch in Git which contains filename case changes?

case-sensitive, filenames, git

Solution

This appears to be a bug in `git-apply` where it cannot handle case-changing renames on case-insensitive filesystems. Unfortunately, this is true even when the patch contains an add and delete of the contents, not just a rename. (So omitting the `-M` flag to `git-format-patch` is unhelpful.)

It seems that you have three options, depending on your desired level of pain:

- Apply the patch on a case sensitive filesystem and pull the resultant commit into your repository.

- Edit the patch manually, changing the resultant filename to be distinct in your repository (for example `TEMPORARY-FILE-CHANGE-ME`), then rename the file to what you desire after applying the patch

- Report this bug and hope that somebody actually cares enough to fix it before you give up and make these changes to your repository by hand

Problem

I have created a patch which consists of a file name case change: ``` git mv -f confvars.sh ConfVars.sh git commit -am 'test filename case change' git format-patch -M -1 HEAD ``` but when I then try and apply that patch, I get an error: ``` git apply 0001-test-filename-case-change.patch > error: ConfVars.sh: already exists in working directory ``` How can I apply this patch without it throwing an error? **EDIT** To clarify the above example: when applying the patch the file ConfVars.sh doesn't exist, the file confvars.sh does exist which I would expect to be renamed, instead it displays the above error.

Original source

Related problems