Search code examples
gitmacosgithubcase-sensitive

git issues with case sensitivity and special characters


I have a remote repository on github which is synced with my macbook and the live server (unix). Currently, I cannot pull or push from my macbook to remote with the following error:

error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

I have 4 files in my local working copy:

modified:   app/webroot/files/uploads/ABC.png

Untracked files:
(use "git add <file>..." to include in what will be committed)

app/webroot/files/get/Ä Ö ü.pdf
app/webroot/files/uploads/xyz Übc.png
app/webroot/files/uploads/def äbc.png

All 4 related files come from user uploads on the server (which should have probably been ignored by gitignore, but here we are now...)

The first/modified file (ABC.png) is probably because of case insensitivity on my macbook, because there are both abc.png and ABC.png in the repository. However, since these are uploads on a customers server, I can't just delete either of those. So this is the first issue I can't get around right now.

For the other files, I have absolutely no clue how to get rid of them. There are no duplicates with other cases, so I'm suspectiong the special characters. I deleted the whole local repository and cloned it again, it comes with those 4 files right away and anything I tried so far didn't work (git clean -ndx, git reset --hard, git fetch with all kinds of parameters).

Usually pulling and pushing works fine even if there are local untracked or modified files, as long as those files are not affected by the commit. But this time I can't do anything and I really don't know why...

I hope some git specialist can help me out here!


Solution

  • This situation is very difficult to deal with. It's not impossible, but the tools available are not really adequate.

    The issue is just what you suspect: your host OS makes particular demands of file names (path names) that Git doesn't, and that someone using Git has violated. Git doesn't care that someone out there made both ABC.png and abc.png; Git can store both these path names separately; but in your work-tree, where you will do your own work, your computer does care and refuses to allow you to have both files. The file names with umlauts are similar, but somewhat different: in UTF-8 one can express such names as either sequences of composing characters, or using code points that have umlauts "built in" as it were. Git allows either, but MacOS forces you to use the names that MacOS prefers.

    This means that to work with this repository, you must work without using a work-tree—or at least, without using Git's usual work-tree mechanisms. It's possible, but generally far too painful, to do this using git update-index, which lets you work with raw byte strings, and git cat-file -p, which lets you extract underlying Git objects by hash ID.

    The simplest method to deal with this on a Mac is to install Linux in a VM, e.g., using vagrant. You then have a Linux system that does let you have files with both name cases, and that does not try to apply Unicode normalization to UTF-8 names.