git - git origin(bitbucket)中大小写不同的重复文件

标签 git

我正在尝试将文件从 foobar.php 重命名为 FooBar.php,这在 Git 中是一个相当大的挑战。到目前为止,我发现我必须将 ignorecase 的 git 配置值设置为 false(为什么它在 Mac OS X 上设置为 true?)。我已经成功地在我的本地存储库中重命名了这些文件,但是在我将它推送到 BitBucket 之后,我在那里得到了 FooBar.phpfoobar.php。我如何摆脱这些重复项?谢谢。

最佳答案

不区分大小写,保留大小写

您可能遇到的问题是 Mac 上的默认文件系统不区分大小写但保留大小写;在那种情况下 file.phpFile.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/

相关文章:

git - 如何从 git 中损坏的松散文件中恢复

Gitignore 不工作

java - 从java程序运行git命令的问题

windows - 为什么 .gitignore.txt 文件在 windows10 中不显示它的名字?

git - 从 Cpanel git 克隆项目,显示此错误 "ssh remote host identification has changed"

git bash 自动完成在 Windows 7 x64 上很慢

git - 错误 : git checkout-index: unable to create file (Permission denied)

git - 在不使用 Git 的情况下将更改部署到 Heroku 上托管的应用程序

git克隆 pull 请求而不是主分支

git - 管理将多个版本的 repo 统一到一个通用的基本分支中 - 最佳实践工作流程?