Automate git commit of case-sensitive rename on case-insensitve file system

时间:2016-08-31 12:29:41

标签: git tortoisegit

I'm on a case-insensitive file system (Windows) and changed the case of several files (a lot of files are affected, so I'm not eager to do it again).

I expected that committing the changes would be easy. But git is not aware of the changes, so I got stuck.

My feeling is that there must be a way to tell git: "Look at the names as they are currently stored on the disk. Commit them exactly like this, i.e. do git mv Foo foo if the case differs from the file in the index."

I've got TortoiseGit installed but couldn't find such an option. I tried to set core.ignorecase = true but this doesn't seem to make any difference.

Thanks, TF

6 个答案:

答案 0 :(得分:3)

你需要让git在git索引中刷新你的文件,但是,它不会在案例密集型操作系统上发现区分大小写的更改。

相反,您可以强制它使用

更新索引
git rm -r --cached . 
git add .

不要忘记下一步。

source

答案 1 :(得分:1)

在再次调查我的问题之后,我得出的结论是没有解决方案。我最后编写了一个批处理脚本,使用git mv重命名我的文件。

恕我直言,如果Git即使在不区分大小写的文件系统上也会处理区分大小写的文件,那么整个不区分大小写与区分大小写的问题就不会成为问题。当然你不能在Windows或OS X中的“Foo.TXT”旁边放置文件“foo.txt”,但是没有理由,为什么Git在重命名后会轻易忽略Windows或OS X上的差异(因为两个系统都是很好地了解情况)。

答案 2 :(得分:0)

IIRC core.ignorecase = true会自动设置为true在Windows上创建/克隆的git存储库。

如果要重命名文件,可以使用上下文菜单“重命名”选项(您可能需要按住Shift键才能看到它 - 可在TortoiseGit选项中配置)以执行git mv操作

答案 3 :(得分:0)

您可以将根文件夹重命名为name_,提交,然后将其更改回来并提交。

这是有效的,因为当您将根文件夹从name更改为name_时,它会删除name文件夹下的所有文件 - 包括小写和大写版本。

但是,这似乎会导致文件历史记录出现问题,即。 “与上次修订比较”这样的命令找不到最后一次修订。 (因为你将它们全部重新定位到一个提交的不同路径)

答案 4 :(得分:0)

您可以在此处尝试使用此实用程序:https://github.com/tawman/git-unite

(我还没有能够自己尝试,因为作者没有提供最终的exe文件,我在尝试运行构建脚本时遇到了问题。但它似乎是一种可以更轻松地解决这个问题的实用工具。)

答案 5 :(得分:0)

Venryx提供的解决方案是一个很好的解决方案。通过遵循README.md文件中的指示,并在223行的UniteRepository.cs文件中进行了一项更正之后,我能够编译Git-Unite存储库: 将_gitRepository?.Dispose();更改为_gitRepository.Dispose();

拥有可执行文件后,只需将其应用于:git.unite.exe [OPTIONS] [repository_folder]。这就像冠军。