安志合的学习博客 安志合的学习博客 -

Git大小写不敏感导致提交文件冲突问题解决

问题现象:gitlab仓库上有个大写的文件名,本地改了小写后,提交后远程库上文件名没有变化,导致冲突。解决方法1:使用 git mvgit mvMove or rename files and update the Git index.More information: <https://git-scm.com/docs/git-mv>.- Move a file inside the repo and add the movement to the next commit:   git mv path/to/file new/path/to/file- Rename a file or directory and add the renaming to the next commit:   git mv path/to/file_or_directory path/to/destination- Overwrite the file or directory in the target path if it exists:    git mv --force path/to/file_or_directory path/to/destination解决方法2:设置本地Git大小写敏感$ git config --get core.ignorecasetrue$ git config core.ignorecase false$ git config --get core.ignorecasefalse关于 是否区分大小写 的补充说明针对文件/文件夹,Windows 系统和 Mac 系统是不区分大小写的;Linux 系统是区分大小写的;Git 默认是不区分大小写的,也可以通过改配置项,改为区分大小写。不分区大小写,也有它的好处,比如:文件夹/文件的路径,很多时候就代表了网站地址、页面url的路径。而网站地址也是不区分大小写的,这是很关键的原因之一。关于 Git是否区分大小写 的补充Git 默认是不区分大小写的,可以通过命令git config --get core.ignorecase查到,默认值是 true。我们也可以修改 Git 的这一配置项,改为区分大小写,配置命令为git config core.ignorecase false。不管是 Windows 还是其他系统下,还是不要轻易修改 git 默认的 core.ignorecase 配置,使用规范的 git mv 做法就好。参考:Git 仓库中文件名大小写问题一个因Git大小写不敏感引发的血案解决 Git 不区分大小写导致的文件冲突问题

本文介绍了解决gitlab仓库中文件名大小写不一致的问题的两种方法:使用git mv命令移动或重命名文件,并设置本地Git大小写敏感。同时补充了关于文件路径和Git是否区分大小写的说明。建议使用规范的git mv命令来解决问题。

git

相关推荐 去reddit讨论