Git:文件重命名

发布于 2024-09-27 16:38:43 字数 156 浏览 1 评论 0原文

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

git add Frameworks/ -f 没有帮助

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?

A git add frameworks/ -f didn't help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

誰ツ都不明白 2024-10-04 16:38:43

您可以尝试:

  • “git mv -f foo.txt Foo.txt”(注意:这不再是从 git 2.0.1 开始需要)
  • 在配置文件中将 ignorecase 设置为 false。

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

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

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

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

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

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

Mac OS X 文件系统默认不区分大小写。 FFFFFF.gifffffff.gif 相同。

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

步骤非常简单:

$ rm file/in/question.gif
$ git 合并主干

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

mv oldname newname
git add newname
git rm oldname

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

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)

there is always an option to set ignorecase to 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.txt
and A.txt are the same thing - so Git tries to preserve that as most users would expect

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.

This blog post illustrates the same issue on MacOs during a rebase:

The default on Mac OS X file systems is that they are case-insensitive. FFFFFF.gif is 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

Anyhow, remember what git mv stands for:

mv oldname newname
git add newname
git rm oldname

, so if newname and oldname clash, 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

两仪 2024-10-04 16:38:43

如果你碰巧在 Github 上托管,你可以使用他们网站上的重命名功能。不得不更换 5 个文件的外壳,发现效果非常好。

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.

肤浅与狂妄 2024-10-04 16:38:43

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文