如何在OS X上清除git中的大小写敏感问题? [英] How to weed out case-sensitivity issues in git on OS X?

查看:115
本文介绍了如何在OS X上清除git中的大小写敏感问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试时

  git mv dir1 / File.py dir2 

我得到

 致命:不受版本控制,来源= dir1 / File.py,destination = dir2 / File.py 

调试我运行

  git ls-files | grep File.py 

幸运的是,我有 alias grep =grep -i ,问题很清楚。 file.py 受版本控制。 File.py 不是。



我猜我曾经重命名过 file.py File.py (在OS X上,这通常需要通过第三个名称)。 Git继续将这两个文件视为相同,因为OS X将它们视为一个文件。但git拒绝移动一个文件,除非这个case也匹配。



我怎样系统地确定是否存在潜伏在git repo中的类似大小写敏感问题?



我使用 OS X extended(Journaled)的默认格式,即 not 大小写 - 敏感,我想保持它。



更新



我刚刚注意到这个相关帖子。

解决方案

这有点不好意思,但它应该在Bash中工作:

  git ls-files | xargs -I {} sh -c'ls{}*&> / dev / null || echo {}'

目标是运行一个显示文件实际情况的命令。 / p>

考虑一下:

  $ ls 
A.md

我们有一个名为的文件A.md 。但是:

  $ ls a.md 
a.md

什么?即使实际名称是 A.md
,shell将它匹配为 a.md -

幸运的是,当我们使用globs时,它的工作方式不同:

  ls:a.md *:没有这样的文件或目录
$ ls A.md *
A.md

这就是我们要找的:通过执行 ls the-file * ,我们可以验证该确切名称是否真的存在。



为此, nocaseglob 选项Bash必须是 off :

  shopt -u nocaseglob 

最高层的命令运行版本库中的每个文件:

  ls{}*&> / dev / null || echo {} 

这里, {} 是循环迭代中文件的名称
,并且我们尝试执行 ls {} * ,放弃命令的输出
和如果命令失败,我们会打印我们尝试的文件名。
如果文件不存在,则命令失败:
例如,因为文件名的大小写不同。



命令的输出顶部将是Git存储库中的文件列表,但不能用相同的名称找到。
这些是您需要修复的文件。



局限性:在某些情况下,该命令可能无法正常运行:




  • 如果您有多个具有相同开头的文件

  • 如果您的文件名中包含换行符



最后,您可以在不通过 Finder 中的第三个中介名称的情况下更改文件大小写。



如果您的工作树没有变化,那么修复名称的一种简单方法是将它们从工作区中删除,然后结帐:

  git ls-files | xargs -I {} sh -c'ls{}*&> / dev / null || echo {}'| xargs rm 
git checkout。


When trying

git mv dir1/File.py dir2

I get

fatal: not under version control, source=dir1/File.py, destination=dir2/File.py

To debug I run

git ls-files | grep File.py

Luckily I had alias grep="grep -i" and the problem is clear. file.py is under version control. File.py isn't.

I'm guessing that I have once renamed file.py to File.py from the shell (on OS X this usually requires going through a third name). Git continued to treat the two files as the same, because OS X treats them as one. But git refuses to move a file unless the case also matches.

How do I systematically determine whether there are similar case sensitivity problems lurking within a git repo?

I'm using the default formatting of OS X extended (Journaled), which is not case-sensitive, and I'd like to keep it that way.

Update

I just noticed this relevant post.

解决方案

This is a bit hacky, but it should work, in Bash:

git ls-files | xargs -I{} sh -c 'ls "{}"* &>/dev/null || echo {}'

The goal is to run a command that reveals the actual case of the file.

Consider this:

$ ls
A.md

We have a single file named A.md. But then:

$ ls a.md
a.md

What? Even though the actual name is A.md, the shell matches it to a.md -- the wrong case.

Luckily, this works differently when we use globs:

$ ls a.md*
ls: a.md*: No such file or directory
$ ls A.md*
A.md

This is what we're looking for: by doing ls the-file*, we can verify if that exact name really exists or not.

For this to work, the nocaseglob option of Bash must be off:

shopt -u nocaseglob

The command at the very top runs for each file in the repository this shell:

ls "{}"* &>/dev/null || echo {}

Here, {} is the name of the file in the loop iteration, and we try to do a ls {}*, discard the output of the command, and if the command failed, we print the filename that we tried. The command fails if the file doesn't exist: for example because the case of the filename is different.

The output of the command at the top will be the list of files that are in your Git repository, but cannot be found by the same name. These are the files you need to fix.

Limitations: the command may not work well in some cases:

  • If you have multiple files with the same beginning
  • If you have files with newline in the name

Lastly, you can change the case of a file without going through a 3rd intermediary name in Finder.

If you have no changes in your working tree, then a simple way to fix the names is to remove them from the workspace and then checkout:

git ls-files | xargs -I{} sh -c 'ls "{}"* &>/dev/null || echo {}' | xargs rm
git checkout .

这篇关于如何在OS X上清除git中的大小写敏感问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆