在Git中更改文件名的大小写
本文翻译自:Changing capitalization of filenames in Git
I am trying to rename a file to have different capitalization from what it had before: 我正在尝试重命名文件以使其具有与之前不同的大小写:
git mv src/collision/b2AABB.js src/collision/B2AABB.js
fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js
As you can see, git throws a fit over this. 如您所见,git对此进行了拟合。 I tried renaming using just the plain old mv
command as well but git doesn't pick up the rename (as a rename or as a new untracked file). 我也尝试仅使用普通的旧mv
命令来重命名,但是git不会选择重命名(作为重命名或作为新的未跟踪文件)。
How can I change a file to have a different capitalization of the same name? 如何更改文件名称的大小写不同? I am on Mac OS X 10.7.3 with git 1.7.9.1 using zsh 4.3.15. 我在使用zsh 4.3.15的git 1.7.9.1的Mac OS X 10.7.3上。
#1楼
参考:https://stackoom.com/question/i9jV/在Git中更改文件名的大小写
#2楼
File names under OS X are not case sensitive (by default). OS X下的文件名不区分大小写(默认情况下)。 This is more of an OS problem than a git problem. 这比git问题更多是OS问题。 If you remove and re-add the file you should get what you want, or rename it to something else and thn rename it back. 如果删除并重新添加文件,则应该得到所需的文件,或将其重命名为其他名称,然后重命名。
#3楼
考虑到以上答案,您可以使用“ --force”使用单个命令进行操作:
git mv --force myfile MyFile
#4楼
Sometimes you want to change the capitalization of a lot of files on a case insensitive filesystem (eg on OS X or Windows). 有时,您想更改不区分大小写的文件系统(例如,在OS X或Windows上)上许多文件的大小写。 Doing git mv
commands will tire quickly, to make things a bit easier this is what I do: 进行git mv
命令很快就会使我感到厌倦,这是我要做的:
- Move all files outside of the directory to lets say the Desktop. 将所有文件移到目录之外,可以说是桌面。
- Do a
git add . -A
做一个git add . -A
git add . -A
to remove all files.git add . -A
删除所有文件。 - Rename all files on the Desktop to the proper capitalization. 将桌面上的所有文件重命名为正确的大小写。
- Move all the files back to the original directory. 将所有文件移回原始目录。
- Do a
git add .
做一个git add .
git should see that the files are renamed. git应该看到文件已重命名。
Now you can make a commit saying you have changed the file capitalization. 现在,您可以进行一次提交,说您已更改文件大小写。
#5楼
Starting git 2.0.1 (June 25th, 2014), a git mv
will just work on case insensitive OS . 从git 2.0.1(2014年6月25日)开始, git mv
将仅在不区分大小写的OS上工作 。
See commit baa37bf by David Turner ( dturner-tw
) 参见David Turner( dturner-tw
)的 commit baa37bf
mv
: allow renaming to fix case on case insensitive filesystems mv
:允许重命名以修复不区分大小写的文件系统上的大小写
" git mv hello.txt Hello.txt
" on a case insensitive filesystem always triggers " destination already exists
" error, because these two names refer to the same path from the filesystem's point of view, and requires the user to give " --force
" when correcting the case of the path recorded in the index and in the next commit. 不区分大小写的文件系统上的“ git mv hello.txt Hello.txt
”始终会触发“ destination already exists
”错误,因为从文件系统的角度来看,这两个名称指的是同一路径,并且要求用户提供--force
更正索引中和下一次提交中记录的路径的大小写。
Detect this case and allow it without requiring "
--force
". 检测这种情况,并允许它而不需要“--force
”。
git mv hello.txt Hello.txt
just works (no --force
required anymore). git mv hello.txt Hello.txt
可以正常工作了(不再需要--force
了)。
#6楼
This python snippet will git mv --force
all files in a directory to be lowercase, ex: foo/Bar.js will become foo/bar.js via git mv foo/Bar.js foo/bar.js --force
此python代码段将git mv --force
目录中的所有文件都转换为小写,例如:foo / Bar.js将通过git mv foo/Bar.js foo/bar.js --force
Modify it to your liking, just figured I'd share :) 修改它以符合您的喜好,只是想我会分享:)
import os
import researchDir = 'c:/someRepo'
exclude = ['.git', 'node_modules','bin']
os.chdir(searchDir)for root, dirs, files in os.walk(searchDir):dirs[:] = [d for d in dirs if d not in exclude]for f in files:if re.match(r'[A-Z]', f):fullPath = os.path.join(root, f)fullPathLower = os.path.join(root, f[0].lower() + f[1:])command = 'git mv --force ' + fullPath + ' ' + fullPathLowerprint(command)os.system(command)
在Git中更改文件名的大小写相关推荐
- 如何在Git中更改多次提交的作者和提交者名称以及电子邮件?
我当时正在学校计算机上编写一个简单的脚本,然后将更改提交到Git(在笔驱动器中的一个回购中,该回购是从家里的计算机中克隆的). 经过几次提交后,我意识到我正在以root用户身份提交东西. 有什么办法可 ...
- 如何在PowerPoint中更改文本的大小写
If you're looking to quickly change the case of the text in a slide of your PowerPoint presentation, ...
- Linux批量文件名大小写转换,Linux中批量把目录内文件名转换大小写用tr
如何将一个目录中所有文件名由大写变为小写 我们以目录 tmp 为例 1. 进入 tmp 目录的上一级目录 2. zip -r tmp.zip tmp/* 3. mv tmp tmp-old (这是为了 ...
- 如何将当前更改提交到git中的不同分支[重复]
本文翻译自:How to commit my current changes to a different branch in git [duplicate] This question alread ...
- linux篡改url命令,在Linux中更改Git远程URL(Git Remote URL)的方法
本文说明了如何更改Git远程的URL,在Linux平台中已测试成功.Git remote是一个指针,它指向通常托管在远程服务器上的存储库的另一个副本,在某些情况下,例如当远程存储库迁移到另一个主机时, ...
- git 撤销更改_如何撤消Git中的更改
git 撤销更改 You may already know that Git is like a save point system. What you generally learn with Gi ...
- 在Git中,HEAD,工作树和索引之间有什么区别?
有人能告诉我在Git中HEAD,工作树和索引之间的区别吗? 据我所知,它们都是不同分支的名称. 我的假设是否正确? 编辑 我找到了这个 单个git存储库可以跟踪任意数量的分支,但是您的工作树只与其中一 ...
- 如何解决Git中的合并冲突
如何解决Git中的合并冲突? #1楼 对于想要半手动解决合并冲突的Emacs用户: git diff --name-status --diff-filter=U 显示所有需要解决冲突的文件. 依次打开 ...
- 当git上只做文件大小写重命名的修改时,如何躲坑...
一. 提交时 假设修改ABC.java为Abc.java. 1.1 如果使用git命令进行仅涉及大小写的重命名 1.1.1 设置git库为大小写敏感(不建议) $ git config core.ig ...
最新文章
- ftp 425 问题
- ubuntu16.04+cuda7.5
- ios开发 多人语音聊天_手游语音市场的现状、机遇与挑战
- springboot获取项目路径_springboot学习
- 新疆农业大学的计算机专业的分数线是多少,2017新疆农业大学科学技术学院专业排名及分数线...
- Java中,异常处理try catch的作用域是局部的
- 【Adobe Air程序开发】用Adobe Flex3开发AIR应用程序–入门指南
- 拼多多摄像头是否安全的检测
- Discuz! ML远程代码执行(CVE-2019-13956)
- ASCII字符绘图网站推荐及使用Python绘制ASCII字符画
- AT32 XMC驱动PC卡/CF卡
- 古诗词学习-归园田居+牧童+凉州词·其一+马诗+逢雪宿芙蓉山主人+凉州词+别董大+枫桥夜泊+滁州西涧+渔歌子+塞下曲
- 数学建模——计算机工具的使用(1)——SPSS操作以及在统计分析中的应用
- python求真分数_Python 列出最简真分数序列*
- 一站购遍全球 史上最长亚马逊Prime会员日即将开启
- 2019CISCN web题赛-JustSoSo;love_math(复现)
- 计算机网络技术的就业前景
- 初识Java ~ (二) # Java 中程序的执行流程,(万字长文)特别细~ 可收藏~
- 通灵学院|游戏设计研习6:制作谜题的原则★(1800字)
- Ueditor 图片上传配置