git origin中有不同大小写的重复文件(bitbucket) [英] Duplicated file with different case in git origin (bitbucket)

查看:167
本文介绍了git origin中有不同大小写的重复文件(bitbucket)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

不区分大小写,保存案例



您可能遇到的问题是Mac上的默认文件系统不区分大小写,但保留了案例;在这种情况下不可能同时存在 file.php File.php - 它们是

这很容易证明:

  $ cd / tmp 
$ mkdir示例
$ cd示例/
$ git init
在/private/tmp/so/.git/中初始化的空Git存储库
$ touch readme
$ git add readme
$ git commit -m添加自述文件
[master(root-commit)05fdf7d]添加自述文件
0文件已更改
create模式100644自述文件
$ mv自述文件x
$ git status
#在分支主机上
#不会为commit提交更改:
#(使用git add / rm < ; file> ...来更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#已删除:自述文件

#未记录文件:
#(使用git add< file> ...来包含将要提交的内容)

#x
没有更改添加到c ommit(使用git add和/或git commit -a)
$ mv x README
$ git status
#在分支主机上
不需要提交(工作目录干净)
$ ls -l
共0
-rw-r - r-- 1 andy wheel 0 Aug 1 19:38自述文件

在上面的文件现在被命名为 README ,但是根据git文件 readme 存在且未修改。

使用两次提交



重命名该文件(在不区分大小写的系统上存在问题)将其分为两步:

  $ mv file.php / tmp 
$ git rm file.php
$ git commit -m删除文件
$ git push

确保存储库中不需要的文件消失。然后,将文件移回到正确的位置并添加它。

  $ mv /tmp/file.php File.php 
$ git add File.php
$ git commit -m添加文件


I am trying to rename files from foobar.php to FooBar.php which is quite a challenge in Git. So far I have found out that I had to set up the git config value of ignorecase to false (why it was set to true on Mac OS X, anyway?). I have managed to rename those files successfully in my local repository, but after I pushed it to BitBucket I've got FooBar.php as well as foobar.php there. How do I get rid of these duplicates? Thanks.

解决方案

Case-insensitive, case-preserving

The problem you likely have is that the default file system on a mac is case-insensitive but case preserving; it is not possible in that circumstance for file.php and File.php to exist at the same time - they are considered the same file.

This is easy to demonstrate:

$ 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

In the above the file is now named README yet according to git the file readme exists and is unmodified.

Use two commits

So instead of renaming the file (which on a case-insensitive system is problematic) do it as two steps:

$ mv file.php /tmp
$ git rm file.php
$ git commit -m "deleting file"
$ git push

Make sure that the undesired file is gone from the repository. Then, move the file back to the right location and add it.

$ mv /tmp/file.php File.php
$ git add File.php
$ git commit -m "adding File"   

这篇关于git origin中有不同大小写的重复文件(bitbucket)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆