为什么 git 将我的分支名称前缀大写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15371866/
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
Why is git capitalizing my branch name prefix?
提问by Collin Allen
I have a really straightforward set of git commands that is resulting in some curious behavior:
我有一组非常简单的 git 命令,导致了一些奇怪的行为:
Show my current local branches, and see that I'm on release/beta1
:
显示我当前的本地分支机构,看看我在release/beta1
:
$ git branch
develop
master
* release/beta1
Create a bugfix/somefeature
branch from release/beta1
:
bugfix/somefeature
从release/beta1
以下位置创建一个分支:
$ git checkout -b bugfix/somefeature
Switched to a new branch 'bugfix/somefeature'
So far so good, right? Well, show me local branches again:
到目前为止一切顺利,对吧?好吧,再给我看看当地的分支机构:
$ git branch
BUGFIX/somefeature
The questions:
问题:
- Why did the
bugfix
prefix of my branch get capitalized asBUGFIX
? - Related, why is that not marked with an asterisk as my current branch?
- 为什么
bugfix
我的分支的前缀被大写为BUGFIX
? - 相关,为什么没有用星号标记为我当前的分支?
I'm using git version 1.8.1.5 via Homebrew on OS X 10.8.2, and this happens with or without my pretty tame ~/.gitconfig
in place. This happens for seemingly every bugfix/...
branch.
我在 OS X 10.8.2 上通过 Homebrew 使用 git 版本 1.8.1.5,无论是否有我的漂亮温顺~/.gitconfig
,都会发生这种情况。似乎每个bugfix/...
分支都会发生这种情况。
回答by poke
Branches are stored as fileswithin the .git
directory. A single branch is a single file containing the hash to the commit object the branch points to.
分支作为文件存储在.git
目录中。单个分支是包含分支指向的提交对象的散列的单个文件。
So, as you maybe guess, when creating a branch foo/bar
this will correspond to a directory with a file. So Git will create a folder foo
with a file bar
which then points to the commit.
因此,正如您可能猜到的,在创建分支时,foo/bar
这将对应于一个包含文件的目录。因此,Git 将创建一个文件夹foo
,bar
其中包含一个指向提交的文件。
This means when you add another branch foo/baz
it will create a file baz
and add that to the folder.
这意味着当您添加另一个分支时foo/baz
,它将创建一个文件baz
并将其添加到文件夹中。
Now branch names are case insensitive for case insensitive file systems. This means that FOO/bar
and foo/bar
are the same. But the actual internalname is taken from the original folder and file name. So when the folder for your bugfix
branch category is written in upper case, then the branches are recognized with an upper case BUGFIX
.
现在,对于不区分大小写的文件系统,分支名称不区分大小写。这意味着FOO/bar
和foo/bar
是相同的。但实际的内部名称取自原始文件夹和文件名。因此,当您的bugfix
分支类别的文件夹以大写形式写入时,分支将被识别为大写BUGFIX
。
To fix this, just go into .git/refs/heads
and change the folder name to the way you like.
要解决此问题,只需进入.git/refs/heads
并将文件夹名称更改为您喜欢的方式即可。
回答by drdwilcox
Thanks for the answer, it helped me find the solution to my problem, but mine was a little different. In my case, the folder with the capitalized name was not in .git/refs/heads
, but in .git/refs/remotes
.
感谢您的回答,它帮助我找到了问题的解决方案,但我的有点不同。在我的情况下,与大写名称的文件夹不在.git/refs/heads
,但在.git/refs/remotes
。
Some time, long ago, someone had created two remote folders that differed only by the capitalization of the first letter. The capitalized version had been abandoned; but my repo, being from before that time, still had the capitalized spelling.
很久以前,有人创建了两个远程文件夹,它们的区别仅在于第一个字母的大小写。大写版本已被放弃;但我的回购,在那个时间之前,仍然有大写的拼写。
So every time I tried to pull from the new folder, it would work, but git put the local branch into the capitalized folder locally. The symptom was that I couldn't pull new changes to that branch; I had to delete my local copy and check the remote out again, every time.
所以每次我尝试从新文件夹中拉取时,它都会工作,但是 git 将本地分支放入本地大写文件夹中。症状是我无法向该分支拉取新更改;我不得不每次都删除我的本地副本并再次检查遥控器。
My fix was to change the spelling of the folder name in .git/refs/remotes
, and the problem has been resolved.
我的解决方法是更改 中文件夹名称的拼写,.git/refs/remotes
问题已解决。
回答by Abhijeet Kamble
To fix this issue, you should follow what @poke said and to disable this I have used the local git commands which can switch the ignore case to false.
要解决此问题,您应该按照@poke 所说的进行操作并禁用此功能,我使用了本地 git 命令,可以将忽略大小写切换为 false。
To identify this, you can check the ignorecase by running the below command.
要识别这一点,您可以通过运行以下命令来检查 ignorecase。
git config --global --get core.ignorecase
this command will return true
which indicates that git is ignoring cases. To fix this make it as false by below command.
此命令将返回true
,表明 git 忽略大小写。要解决此问题,请通过以下命令将其设为 false。
git config --global core.ignorecase false
This will disable the ignorecase in git. Hope this will fix this issue. Make sure you are not working on multi language projects, this setting might require true in that case.
这将禁用 git 中的 ignorecase。希望这会解决这个问题。确保您不是在处理多语言项目,在这种情况下,此设置可能需要 true。