在 Windows 上更改文件的大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1793735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change case of a file on Windows?
提问by Electrons_Ahoy
There are a couple of files in our git-controlled codebase that I'd like to rename. Specifically, I just want to change the case of the file, so that sourceCode.java
becomes SourceCode.java
, for example. The catch: I'm on a Windows box, and the filesystem thinks those are the same file name.
我们的 git 控制的代码库中有几个文件我想重命名。具体来说,我只想更改文件的大小写,例如,sourceCode.java
变成SourceCode.java
。问题:我在 Windows 机器上,文件系统认为它们是相同的文件名。
How can I get Windows and Git to recognize that change and check it in?
如何让 Windows 和 Git 识别该更改并将其签入?
回答by Igor Zevaka
Have a look here for more hints on how to do it:
查看此处以获取有关如何执行此操作的更多提示:
How to make git ignore changes in case?
Or:
或者:
git mv -f name.java Name.java
回答by ChrisF
If you are on a FAT file system your only choice is to do a two stage rename:
如果您使用的是 FAT 文件系统,您唯一的选择是进行两阶段重命名:
- Rename
sourceCode.java
toanything.you.like
- Rename
anything.you.like
toSourceCode.java
- 重命名
sourceCode.java
为anything.you.like
- 重命名
anything.you.like
为SourceCode.java
Back in the days when we used Perforce we had exactly this problem and this was the only solution we could come up with.
在我们使用 Perforce 的日子里,我们遇到了这个问题,这是我们能想出的唯一解决方案。
回答by Pieter van Ginkel
The following steps allowed me to change the case on Windows:
以下步骤允许我在 Windows 上更改大小写:
- Add
ignorecase = false
to[core]
in.git/config
; - Move the files you are going to rename out of your project directory;
- Add the deletes to the index;
- Move all files back to their original location and change the case of the files and/or directories;
- Add all "new" files to the index;
- Remove
ignorecase = false
added at the first step.
- 加入
ignorecase = false
到[core]
中.git/config
; - 将要重命名的文件移出项目目录;
- 将删除添加到索引中;
- 将所有文件移回其原始位置并更改文件和/或目录的大小写;
- 将所有“新”文件添加到索引中;
- 删除
ignorecase = false
第一步添加的。
This way you have a single commit that contains the rename and it makes it easy to change e.g. an entire directory.
通过这种方式,您有一个包含重命名的提交,并且可以轻松更改例如整个目录。
回答by jwg
Be careful. Doing this can lead to changes that are impossible to merge. Git gets confused when merging on Windows because it can't decide whether the old Uppercase name and the new lowercase name are the same file or not (for Git they are not, but for the filesystem they are). To merge you have to do some manual workaround like deleting the files before merging.
当心。这样做可能会导致无法合并的更改。Git 在 Windows 上合并时会感到困惑,因为它无法决定旧的大写名称和新的小写名称是否是同一个文件(对于 Git 来说它们不是,但对于文件系统它们是)。要合并,您必须执行一些手动解决方法,例如在合并之前删除文件。
See Git rebase issue with files of same name but different case
请参阅具有相同名称但大小写不同的文件的 Git rebase 问题
I'm not sure if this issue is worse than having an unconventionally-named file in your project for ever and ever, but it is worth knowing about if there are lots of users with lots of branches which will all need to be merged eventually.
我不确定这个问题是否比永远在您的项目中使用非常规命名的文件更糟糕,但值得了解是否有很多用户拥有很多分支,最终都需要合并。
回答by Nils-o-mat
In my opinion one simple way is missing. You can do this for a single file, a specific directory or even the whole repository:
在我看来,缺少一种简单的方法。您可以对单个文件、特定目录甚至整个存储库执行此操作:
git rm --cached <file name or directory>
git add <file name or directory>
If you want to affect also the sub-directories, you have to use the -r
flag:
如果您还想影响子目录,则必须使用该-r
标志:
git rm -r --cached <directory>
git add <directory>
回答by Rainer Blome
With NTFS (or FAT), a single git mv
command does not solve the problem.
This question shows a technique that works:
git mv and only change case of directory
对于 NTFS(或 FAT),单个git mv
命令并不能解决问题。这个问题展示了一种有效的技术:
git mv and only change case of directory