Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 523
Martyn Avatar asked Oct 02 '22 15:10

Martyn


2 Answers

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
like image 168
Edward Thomson Avatar answered Oct 11 '22 15:10

Edward Thomson


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.

like image 43
HHenn Avatar answered Oct 11 '22 13:10

HHenn