简体   繁体   English

git区分大小写和特殊字符的问题

[英]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). 我在github上有一个远程存储库,该存储库与我的Macbook和实时服务器(unix)同步。 Currently, I cannot pull or push from my macbook to remote with the following error: 目前,我无法从Macbook将遥控器拉出或推入遥控器,但出现以下错误:

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

I have 4 files in my local working copy: 我的本地工作副本中有4个文件:

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...) 所有4个相关文件都来自服务器上的用户上传(gitignore应该可能已将其忽略,但是现在我们在这里...)

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. 第一个/修改后的文件(ABC.png)可能是因为我的Macbook不区分大小写,因为存储库中同时存在abc.png和ABC.png。 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). 我删除了整个本地存储库,然后再次克隆了它,它立即附带了这4个文件,到目前为止,我尝试的任何操作均不起作用(git clean -ndx,git reset --hard,带有各种参数的git fetch)。

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! 我希望一些git专家可以在这里帮助我!

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不需要的文件名(路径名)有特殊要求,并且有人使用Git违反了该文件名。 Git doesn't care that someone out there made both ABC.png and abc.png ; Git不在乎有人在那里制作了ABC.pngabc.png ; Git can store both these path names separately; Git可以分别存储这两个路径名; 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. 带有变音符号的文件名类似,但有所不同:在UTF-8中,可以将名称表示为组成字符的序列,也可以使用带有“内置”变音符的代码点。 Git allows either, but MacOS forces you to use the names that MacOS prefers. Git允许任何一种,但是MacOS会强制您使用MacOS首选的名称。

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. 这意味着要使用此存储库,您必须不使用工作树,或者至少不使用Git常用的工作树机制。 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. 可以使用git update-indexgit cat-file -p来执行此操作,但总的来说太痛苦了,该git update-index使您可以使用原始字节字符串,而git cat-file -p可以使您通过哈希ID提取底层Git对象。

The simplest method to deal with this on a Mac is to install Linux in a VM, eg, using vagrant. 在Mac上解决此问题的最简单方法是,例如,使用流浪汉,将Linux安装在VM中。 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. 那么你有一个Linux系统, 让你有与两个名字案件的文件,并且不试图为Unicode正常化适用于UTF-8名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM