6

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.

Martyn
  • 16,432
  • 24
  • 71
  • 104
  • It appears you are attempting to apply the patch in a repository that either already has that commit in it, or the `ConfVars.sh` file possibly was created by a different commit, or exists as an unstaged or uncommitted change in your working directory... – twalberg Feb 10 '14 at 16:40
  • 1
    I don't think I am - this behaviour is independent of state and is meant to ask in a generic format - how can I apply a filename case change as given in a patch. To clarify the example above the file ConfVars.sh doesn't exist - only the file confvars.sh exists which i would expect to be renamed, instead it displays the above error – Martyn Feb 12 '14 at 12:43
  • What platform is this? Do you in fact have a file system that is case sensitive (i.e. Linux), or one that is case-agnostic like NTFS/FAT (i.e. Windows)? – twalberg Feb 12 '14 at 15:19
  • Do you have `core.ignorecase` set? `git config --get core.ignorecase` and/or `git config --global --get core.ignorecase` to check... – twalberg Feb 12 '14 at 17:28

2 Answers2

5

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:

  1. Apply the patch on a case sensitive filesystem and pull the resultant commit into your repository.
  2. 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
  3. 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
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • That said, I didn't notice your comment that this is on Linux; case-changing renames seem to work for me on a case-sensitive filesystem. Are you on a case-insensitive filesystem? USB stick or something? – Edward Thomson Feb 12 '14 at 18:16
2

If you are running Windows 10 (>= 1803, april 2018), you can enable the NTFS case sensitivity by typing the following command (administrator privileges may be required):

fsutil.exe file setCaseSensitiveInfo C:\SampleFolder enable

Now the git apply command should work.

Remarks: Existing subfolders are not affected.

HHenn
  • 309
  • 3
  • 4