Git:文件重命名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3921153/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:16:23  来源:igfitidea点击:

Git: File Rename

macosgitcase-insensitive

提问by Erik Aigner

I wanted to rename a folder from "Frameworks" to "frameworks", but git would not let me add the new lowercase name. I guess it treats filenames case insensitive, does it?

我想将文件夹从“ Frameworks”重命名为“ frameworks”,但 git 不允许我添加新的小写名称。我猜它对待文件名不区分大小写,是吗?

A git add frameworks/ -fdidn't help

Agit add frameworks/ -f没有帮助

回答by VonC

You can try:

你可以试试:



But the issue of case (on Windows for instance) is described in the msysgit issue 228(again: this should now -- June 2014 -- work with git 2.0.1)

但是案例问题(例如在 Windows 上)在msysgit 问题 228中进行了描述(再次:这现在应该- 2014 年 6 月 - 与 git 2.0.1 一起使用

there is always an option to set ignorecaseto false in the config file that will force Unix like Git semantics on top of NTFS.
Git supports this behavior but it is not the default - from NTFS point of view a.txtand A.txtare the same thing - so Git tries to preserve that as most users would expect

ignorecase在配置文件中总是有一个选项可以设置为 false,这将强制在 NTFS 之上使用类 Unix 的 Git 语义。
Git 支持这种行为,但它不是默认的——从 NTFS 的角度来看a.txt并且A.txt是一样的——所以 Git 试图保留大多数用户所期望的

As a better workaround, you can

git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt

, which also changes the case of the file as stored on disk.

作为更好的解决方法,您可以

git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt

,这也会改变存储在磁盘上的文件的大小写。

This blog post illustrates the same issue on MacOsduring a rebase:

这篇博文说明了在变基期间 MacO上的相同问题

The default on Mac OS X file systems is that they are case-insensitive. FFFFFF.gifis the same as ffffff.gif.

If you delete the file in question, just from the file system, not from the Git index, mind you, you can merge the branch in question, and have it restore the file as if nothing happened.

The steps are pretty simple:

$ rm file/in/question.gif
$ git merge trunk

Mac OS X 文件系统的默认设置是它们不区分大小写。FFFFFF.gif与 相同ffffff.gif

如果您删除有问题的文件,只是从文件系统中删除,而不是从 Git 索引中删除,请注意,您可以合并有问题的分支,并让它恢复文件,就好像什么也没发生一样。

步骤非常简单:

$ rm file/in/question.gif
$ git merge trunk


Anyhow, remember what git mv stands for:

无论如何,请记住 git mv 代表什么

mv oldname newname
git add newname
git rm oldname

, so if newnameand oldnameclash, you need to make them different (even if it is only for a short period of time), hence the git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt

,所以如果newnameoldname冲突,你需要让它们不同(即使只是很短的时间),因此git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt

回答by kvz

If you happen to host on Github, you can use the rename function on their website. Had to change the casing for 5 files and found it worked really well.

如果您碰巧在 Github 上托管,则可以使用其网站上的重命名功能。不得不更改 5 个文件的大小写,发现它运行得非常好。

回答by David

I was having a similar problem and couldn't get a new folder name (different case) to change on remote repos. I found that the easiest solution was just to move the file out of the repo and commit. Triggering a delete action. Then re-add and when I added, it came in with the proper case.

我遇到了类似的问题,无法在远程存储库上更改新文件夹名称(大小写不同)。我发现最简单的解决方案就是将文件移出 repo 并提交。触发删除操作。然后重新添加,当我添加时,它带有正确的大小写。