我通过将第一个字母去大写来更改了一些文件名,如name.jpg中的name.jpg。Git无法识别这些更改,我不得不删除这些文件并再次上传。在检查文件名的更改时,Git是否可以区分大小写?我没有对文件本身进行任何更改。
当前回答
使用以下命令:
git config --global core.ignorecase false
您可以全局配置git系统,使其对文件和文件夹名称区分大小写。
其他回答
我从其他答案中尝试了以下解决方案,但没有奏效:
git-mv文件名git rm-f文件名
如果您的存储库是远程托管的(GitHub、GitLab、BitBucket),您可以在源站(GitHub.com)上重命名文件,并强制以自顶向下的方式重命名文件。
以下说明适用于GitHub,但其背后的一般思想应适用于任何远程存储库托管平台。请记住,您尝试重命名的文件类型很重要,也就是说,它是GitHub认为在浏览器中可编辑(代码、文本等)还是不可编辑(图像、二进制等)的文件类型。
访问GitHub.com导航到GitHub.com上的存储库并选择您所在的分支使用站点的文件导航工具,导航到要重命名的文件GitHub允许您在浏览器中编辑文件吗?a.)可编辑单击“编辑此文件”图标(看起来像铅笔)更改文件名文本输入中的文件名b.)不可编辑在新选项卡中打开“下载”按钮,并将文件保存到计算机重命名下载的文件在GitHub.com上的上一个选项卡中,单击“删除此文件”图标(看起来像垃圾桶)确保选中“Commit directly to the branchname branch”单选按钮,然后单击“Commit changes”按钮在GitHub.com的同一目录中,单击“上载文件”按钮从计算机上载重命名的文件确保选中“Commit directly to the branchname branch”单选按钮,然后单击“Commit changes”按钮本地,签出/提取/拉动分支多恩
我制作了一个bash脚本,将存储库文件名小写:
function git-lowercase-file {
tmp="tmp-$RANDOM-$1"
git mv -f $1 $tmp
git mv -f $tmp ${1,,}
}
那么你可以这样使用它:
git-lowercase-file Name.jpg
或者只需在git存储库web UI界面上重命名所需文件并提交:)
我接受了@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