Git 分支名称 - 区分大小写还是不区分大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38493543/
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
Git branch name - case sensitive or insensitive?
提问by jak
I am a new git user and recently been handed with an out of date git repository to look after.
我是一个新的 git 用户,最近收到了一个过时的 git 存储库来照顾。
This is the original state ( output by git show-branch):
这是原始状态(由 git show-branch 输出):
! [cr232] CR 232 Release
* [dev] Style Changes
---------------
* [dev] Style Changes
* [dev^] SMS 5.4
* [dev~2] Logo Change
* [dev~3] SMS 5.3
* [dev~4] SMS 5.2
* [dev~5] SIT R-0.3.3 EDW SMS Layers
* [dev~6] SIT Release R 0.3.0
+* [cr232] CR 232 Release
+* [cr232^] Dashboard Fix
+* [cr232~2] Release for system testing
Note that there is a branch called ‘dev' at this point. Note that highlighted there are several references to dev (i.e. dev, dev^, dev~2 etc).
请注意,此时有一个名为“dev”的分支。请注意,突出显示有几个对 dev 的引用(即 dev、dev^、dev~2 等)。
For my development purpose, I was trying to come up with a branch called ‘DEV', all capital.
为了我的开发目的,我试图想出一个名为“DEV”的分支,全是资本。
So I went ahead and create new branch (git branch DEV) and now running git show-branch –date-order:
所以我继续创建新分支(git branch DEV),现在运行 git show-branch –date-order:
! [DEV] Style Changes
! [cr232] CR 232 Release
* [dev] Style Changes
---------------
* [DEV] Style Changes
* [DEV^] SMS 5.4
* [DEV~2] Logo Change
* [DEV~3] SMS 5.3
* [DEV~4] SMS 5.2
* [DEV~5] SIT R-0.3.3 EDW SMS Layers
* [DEV~6] SIT Release R 0.3.0
+* [cr232] CR 232 Release
+* [cr232^] Dashboard Fix
+* [cr232~2] Release for system testing
Note that both dev and DEV are listed as branch. Note also that on the 5th line the references to dev have now changed to DEV (i.e. DEV, DEV^, DEV~2 etc).
请注意,dev 和 DEV 都列为分支。另请注意,在第 5 行,对 dev 的引用现在已更改为 DEV(即 DEV、DEV^、DEV~2 等)。
What is the 5th line output referring to? I would expect it to remain “dev” instead of being changed to “DEV” as the descriptions next to it refers to the description of old work during “dev” branch.
第 5 行输出指的是什么?我希望它保持“dev”而不是更改为“DEV”,因为它旁边的描述指的是“dev”分支期间旧工作的描述。
I am trying to return back to how it was by modifying the DEV branch name to DV (running git branch –m DEV DV) and showing the branch now look like:
我试图通过将 DEV 分支名称修改为 DV(运行 git branch –m DEV DV)并显示分支现在看起来像:
! [DV] Style Changes
! [cr232] CR 232 Release
* [dev] Style Changes
---------------
* [DV] Style Changes
* [DV^] SMS 5.4
* [DV~2] Logo Change
* [DV~3] SMS 5.3
* [DV~4] SMS 5.2
* [DV~5] SIT R-0.3.3 EDW SMS Layers
* [DV~6] SIT Release R 0.3.0
+* [cr232] CR 232 Release
+* [cr232^] Dashboard Fix
+* [cr232~2] Release for system testing
Note that the branch is now including DV and dev. Note also that the 5th line references to dev have now changed to DV (i.e. DV, DV^, DV~2 etc).
请注意,该分支现在包括 DV 和 dev。另请注意,对 dev 的第 5 行引用现在已更改为 DV(即 DV、DV^、DV~2 等)。
Is there any way to get back to how it was during original state in term of the DV references? Did the git got confused and renamed my historic information with a branch that is similar and only differs by capital case?
有什么办法可以恢复到 DV 参考时的原始状态?git 是否感到困惑并使用类似的分支重命名了我的历史信息,并且仅在大小写上有所不同?
Please assist on how I can fix this. Thanks heaps
请帮助我如何解决这个问题。谢谢堆
采纳答案by ElpieKay
So I went ahead and create new branch (git branch DEV)
所以我继续创建新分支(git branch DEV)
You created a new branch DEV
when you were on the branch dev
. So DEV
and dev
are two branches that point to the same commit. After you renamed DEV
to DV
, now DV
and dev
are two branches that point to the same commit.
您在分支DEV
时创建了一个新分支dev
。所以DEV
和dev
是指向同一个提交的两个分支。重命名DEV
为 后DV
,现在DV
和dev
是指向同一个提交的两个分支。
Everything is just fine. If you don't want DV
to bother you, you could just run git branch -d DV
to remove it. If you indeed want to make a new branch, better to follow some naming rule which cannot confuse you and others.
一切都很好。如果你不想DV
打扰你,你可以直接跑去git branch -d DV
删除它。如果您确实想创建一个新分支,最好遵循一些不会混淆您和其他人的命名规则。
I never used git show-branch
. git log --oneline --all --graph --decorate=full
draws a clear log graph.
我从来没有用过git show-branch
。git log --oneline --all --graph --decorate=full
绘制清晰的日志图。
回答by torek
Answering just the question in the subject line, without addressing anything about git show-branch
(like ElpieKay, I never actually use git show-branch
; it seems mainly mis-informative):
只回答主题行中的问题,没有解决任何关于git show-branch
(比如 ElpieKay,我从来没有真正使用过git show-branch
;它似乎主要是错误的信息):
Git branch names—and tag names, and all other referencenames, as Git calls them—were originally intendedto be case-sensitive.
Git 分支名称——和标签名称,以及所有其他引用名称,正如 Git 所称的——最初是要区分大小写的。
This all works perfectly on Linux / Unix machines, where Git's code is case-sensitive to start with. When Git stores branch names in the file system as file names(which it only does sometimes), the file system is also case-sensitive.1
这一切都在 Linux / Unix 机器上完美运行,其中 Git 的代码一开始就区分大小写。当 Git 将文件系统中的分支名称作为文件名存储时(它只是有时这样做),文件系统也是区分大小写的。1
It sometimesfails on Windows and some MacOS systems. Specifically, it fails when Git stores references in individual files, whose names are derived from the reference name, and those file names are case-insensitive (e.g., case-preserving, but fold case during name-matching; or even converting everything to uppercase-only, as in the really old FAT 8.3 format, but we can hope no modern file system does this).
它有时会在 Windows 和某些 MacOS 系统上失败。具体来说,当 Git 将引用存储在单个文件中时它会失败,这些文件的名称来自引用名称,并且这些文件名不区分大小写(例如,保留大小写,但在名称匹配过程中折叠大小写;甚至将所有内容都转换为大写-仅,就像在真正旧的 FAT 8.3 格式中一样,但我们希望没有现代文件系统可以做到这一点)。
As noted above, Git does not always store reference names as file names. In fact, on initial clone, all the names are in a single file called .git/packed-refs
,2so at this point they arecase sensitive. But they become "unpacked" over time,3and then on some systems they become case-folding.
如上所述,Git 并不总是将引用名称存储为文件名。事实上,初始克隆,所有的名字都叫做一个文件.git/packed-refs
,2所以在这一点上,他们是区分大小写的。但是随着时间的推移,它们会变得“未包装”,3然后在某些系统上它们变成了折叠箱。
Because it sometimes fails on some systems, it's generally best to avoid using multiple reference names that differ only in case.
因为它有时会在某些系统上失败,所以通常最好避免使用多个仅在大小写不同的引用名称。
1Of course, on modern Unix/Linux systems, you can now get access to case-preserving-but-case-insensitive file systems, and Windows and MacOS can now be told not to do case-folding for some file systems. (But if you change from the defaults, expect software that is intended for your box to fail, because it will. Things like Photoshop internally try to use files named foo
and FOO
and expect this to refer to the same file!)
1当然,在现代 Unix/Linux 系统上,您现在可以访问保留大小写但不区分大小写的文件系统,并且现在可以告诉 Windows 和 MacOS 不对某些文件系统进行大小写折叠。(但是,如果您更改了默认设置,预计专为您的盒子设计的软件会失败,因为它会失败。像 Photoshop 之类的东西在内部尝试使用命名的文件foo
,FOO
并希望它引用同一个文件!)
2This packed-references file has been around for quite a while, but not forever, and very early versions of Git may not use it. Internally, Git is acquiring a new "pluggable reference name interface" and future versions of Git might use neither this file, nor individual per-reference files.
2这个打包引用文件已经存在了很长时间,但不是永远存在,并且非常早期的 Git 版本可能不会使用它。在内部,Git 正在获取一个新的“可插入引用名称接口”,并且未来版本的 Git 可能既不使用这个文件,也不使用单独的每个引用文件。
3In general, creating or updating a reference causes an unpacked reference file to come into existence. Running git pack-refs --all
will replace unpacked references with packed ones, restoring full case-sensitivity. Without --all
, git pack-refs
only packs already-packed references, which is largely a useless mode of operation (it was intended for a case that is no longer used).
3一般而言,创建或更新参考会导致解压参考文件出现。运行git pack-refs --all
将用打包的引用替换解压缩的引用,恢复完全区分大小写。没有--all
,git pack-refs
只打包已经打包的引用,这在很大程度上是一种无用的操作模式(它用于不再使用的情况)。