我正在尝试将文件从 foobar.php 重命名为 FooBar.php,这在 Git 中是一个相当大的挑战。到目前为止,我发现我必须将 ignorecase
的 git 配置值设置为 false
(为什么它在 Mac OS X 上设置为 true?)。我已经成功地在我的本地存储库中重命名了这些文件,但是在我将它推送到 BitBucket 之后,我在那里得到了 FooBar.php
和 foobar.php
。我如何摆脱这些重复项?谢谢。
最佳答案
不区分大小写,保留大小写
您可能遇到的问题是 Mac 上的默认文件系统不区分大小写但保留大小写;在那种情况下 file.php
和 File.php
不可能同时存在 - 它们被认为是同一个文件。
这很容易证明:
$ cd /tmp
$ mkdir example
$ cd example/
$ git init
Initialized empty Git repository in /private/tmp/so/.git/
$ touch readme
$ git add readme
$ git commit -m "adding readme"
[master (root-commit) 05fdf7d] adding readme
0 files changed
create mode 100644 readme
$ mv readme x
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: readme
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# x
no changes added to commit (use "git add" and/or "git commit -a")
$ mv x README
$ git status
# On branch master
nothing to commit (working directory clean)
$ ls -l
total 0
-rw-r--r-- 1 andy wheel 0 Aug 1 19:38 README
在上面,文件现在被命名为 README
但根据 git,文件 readme
存在并且未被修改。
使用两次提交
因此,与其重命名文件(在不区分大小写的系统上有问题),不如分两步进行:
$ mv file.php /tmp
$ git rm file.php
$ git commit -m "deleting file"
$ git push
确保不需要的文件从存储库中消失。然后,将文件移回正确的位置并添加它。
$ mv /tmp/file.php File.php
$ git add File.php
$ git commit -m "adding File"
$ git push
关于git - git origin(bitbucket)中大小写不同的重复文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18000138/