git origin (bitbucket) 中具有不同大小写的重复文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18000138/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Duplicated file with different case in git origin (bitbucket)
提问by petiar
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.
我正在尝试将文件从 foobar.php 重命名为 FooBar.php,这在 Git 中是一个很大的挑战。到目前为止,我发现我不得不设立的混帐配置值ignorecase
,以false
(为什么它被设置为true,在Mac OS X,反正?)。我已经成功地在我的本地存储库中重命名了这些文件,但是在我将它推送到 BitBucket 之后,我已经和那里FooBar.php
一样好了foobar.php
。我如何摆脱这些重复?谢谢。
回答by AD7six
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.
您可能遇到的问题是 Mac 上的默认文件系统不区分大小写但保留大小写;在这种情况下不可能同时存在file.php
和File.php
存在 - 它们被认为是同一个文件。
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.
在上面,文件现在README
根据 git命名,文件readme
存在且未修改。
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 gonefrom 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 push
回答by ThomasH
Applied to Directories
应用于目录
As I was struggling with this issue on a directory level (rather than on a file level), here is the recipe applied to a folder (this was on Windows, git v2.9.2).
当我在目录级别(而不是文件级别)上解决这个问题时,这是应用于文件夹的配方(这是在 Windows 上,git v2.9.2)。
- Bitbucketwould be showing two subfolders, say Foobarand FooBar, with different files/folders beneath them.
- On the clientcore.ignorecasewas set to trueand both file trees where merged into one under a common root, say Foobar.
- Don't set core.ignorecaseto falsejust yet, as it will leave you suddenly with "untracked" files from the other path!
git mv Foobar Foobar.tmp
- You will get a set of renamed files, but also a set of deleted files and their corresponding untracked ones from the other path.git add .
- Stage all the deleted/untracked files.- That worked ok for me. Although these appear as deletes/additions, the history of those files is not lost (magically).
git commit -m"syncing Foo[Bb]ar into temp. folder"
- Commit the temp. folder.git mv Foobar.tmp FooBar
- Now rename from temp. to the desired name.git commit -m"moving FooBar into place"
- Commit the target name.git push
- Now Bitbucket should show a single subdirectory FooBar.git config [--global] core.ignorecase false
- Never stumble into that problem again.
- Bitbucket将显示两个子文件夹,比如Foobar和FooBar,它们下面有不同的文件/文件夹。
- 在客户端core.ignorecase设置为true并且两个文件树合并到一个公共根下,例如Foobar。
- 暂时不要将core.ignorecase设置为false,因为它会突然让您看到来自另一条路径的“未跟踪”文件!
git mv Foobar Foobar.tmp
- 您将获得一组重命名的文件,以及一组已删除的文件及其来自其他路径的相应未跟踪文件。git add .
- 暂存所有已删除/未跟踪的文件。- 这对我有用。尽管这些显示为删除/添加,但这些文件的历史记录不会丢失(神奇地)。
git commit -m"syncing Foo[Bb]ar into temp. folder"
- 提交温度。文件夹。git mv Foobar.tmp FooBar
- 现在从临时重命名。到所需的名称。git commit -m"moving FooBar into place"
- 提交目标名称。git push
- 现在 Bitbucket 应该显示一个子目录FooBar。git config [--global] core.ignorecase false
- 再也不会遇到那个问题了。
回答by Carl Norum
Clone/checkout into a case-sensitive file system (on Mac OS X you can just make a case-sensitive disk image to do so), and then git rm
the file with the capitalization you don't want.
克隆/签出到区分大小写的文件系统(在 Mac OS X 上,您只需制作区分大小写的磁盘映像即可),然后复制git rm
您不想要的大写字母的文件。
As to why ignorecase
was set to true, the documentationsays:
至于为什么ignorecase
设置为true,文档说:
core.ignorecase
The default is false, exceptgit-clone(1)
orgit-init(1)
will probe and setcore.ignorecase
true if appropriate when the repository is created.
core.ignorecase
默认值为 false,除非git-clone(1)
或git-init(1)
将core.ignorecase
在创建存储库时探测并在适当时设置为 true。
Since your Mac probably has a case-insensitive filesystem (it's the default), git
will have noticed that and set the flag appropriately.
由于您的 Mac 可能有一个不区分大小写的文件系统(这是默认设置),因此您git
会注意到这一点并适当地设置标志。