我通过将第一个字母去大写来更改了一些文件名,如name.jpg中的name.jpg。Git无法识别这些更改,我不得不删除这些文件并再次上传。在检查文件名的更改时,Git是否可以区分大小写?我没有对文件本身进行任何更改。
当前回答
与@Sijmen的答案类似,这是我在OSX上重命名目录时的工作原理(灵感来自另一篇文章的答案):
git mv CSS CSS2
git mv CSS2 css
简单地执行git-mv-CSS CSS会产生无效参数错误:致命:重命名“/static/CSS”失败:无效参数可能是因为OSX的文件系统不区分大小写
p.s BTW如果您使用的是Django,collectstatic也无法识别大小写差异,您必须在静态根目录中手动执行上述操作
其他回答
只要您只是重命名文件而不是文件夹,就可以使用gitmv:
git mv -f yOuRfIlEnAmE yourfilename
(在Git2.0.1中进行了修改,上面的咒语中的-f标志是多余的,但在较旧的Git版本中需要。)
Mac OSX High Sierra 10.13在一定程度上修复了这一问题。只需为git项目创建一个虚拟APFS分区,默认情况下它没有大小限制,也不占用空间。
在磁盘实用程序中,选择容器磁盘时单击+按钮在格式下选择APFS(区分大小写)命名为敏感利润可选:在Sensitive中创建一个名为git和ln-s/Volumes/Sensitive/git/Users/johndoe/git的文件夹
您的驱动器将位于/卷/敏感/
如何在Git中提交仅区分大小写的文件名更改?
我接受了@CBarr的回答,并编写了一个Python 3脚本,用一个文件列表来实现:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import shlex
import subprocess
def run_command(absolute_path, command_name):
print( "Running", command_name, absolute_path )
command = shlex.split( command_name )
command_line_interface = subprocess.Popen(
command, stdout=subprocess.PIPE, cwd=absolute_path )
output = command_line_interface.communicate()[0]
print( output )
if command_line_interface.returncode != 0:
raise RuntimeError( "A process exited with the error '%s'..." % (
command_line_interface.returncode ) )
def main():
FILENAMES_MAPPING = \
[
(r"F:\\SublimeText\\Data", r"README.MD", r"README.md"),
(r"F:\\SublimeText\\Data\\Packages\\Alignment", r"readme.md", r"README.md"),
(r"F:\\SublimeText\\Data\\Packages\\AmxxEditor", r"README.MD", r"README.md"),
]
for absolute_path, oldname, newname in FILENAMES_MAPPING:
run_command( absolute_path, "git mv '%s' '%s1'" % ( oldname, newname ) )
run_command( absolute_path, "git add '%s1'" % ( newname ) )
run_command( absolute_path,
"git commit -m 'Normalized the \'%s\' with case-sensitive name'" % (
newname ) )
run_command( absolute_path, "git mv '%s1' '%s'" % ( newname, newname ) )
run_command( absolute_path, "git add '%s'" % ( newname ) )
run_command( absolute_path, "git commit --amend --no-edit" )
if __name__ == "__main__":
main()
Git有一个配置设置,告诉它是否需要区分大小写的文件系统:core.ignorecase。要让Git保持大小写稳定,只需将此设置设置为false。(如果您已经推送了文件,请务必小心,然后在给出其他答案后,应首先移动它们)。
git config core.ignorecase false
注意,在不区分大小写的文件系统上,将此选项设置为false通常是一个坏主意。这样做会导致奇怪的错误。例如,以仅更改字母大小写的方式重命名文件将导致git报告虚假冲突或创建重复文件(来自Mark Amery的评论)。
文档
从git-config文档中:
核心.ignorecase如果为true,则此选项启用各种变通方法,使git能够更好地处理不区分大小写的文件系统,如FAT。例如,如果一个目录列表在git期望makefile时找到了makefile,git将假设它实际上是同一个文件,并继续将其记为makefile。默认值为false,但gitclone(1)或gitinit(1)将在创建存储库时探测并将core.ignorecase设置为true(如果合适)。
不区分大小写的文件系统
据我所知,最流行的两种具有不区分大小写文件系统的操作系统是
窗户操作系统X
我制作了一个bash脚本,将存储库文件名小写:
function git-lowercase-file {
tmp="tmp-$RANDOM-$1"
git mv -f $1 $tmp
git mv -f $tmp ${1,,}
}
那么你可以这样使用它:
git-lowercase-file Name.jpg