我通过将第一个字母去大写来更改了一些文件名,如name.jpg中的name.jpg。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
我接受了@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()
这是我在OS X上所做的:
git mv File file.tmp
git mv file.tmp file
两个步骤,否则我会出现“文件存在”错误。也许可以通过添加缓存等一步到位。
我制作了一个bash脚本,将存储库文件名小写:
function git-lowercase-file {
tmp="tmp-$RANDOM-$1"
git mv -f $1 $tmp
git mv -f $tmp ${1,,}
}
那么你可以这样使用它:
git-lowercase-file Name.jpg
我们可以使用gitmv命令。例如,如果我们将文件abcDEF.js重命名为abcDEF.js,那么我们可以从终端运行以下命令
git mv -f .\abcDEF.js .\abcdef.js
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- MySQL区分大小写查询
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式