为什么分支名称不能包含“空格"字符? [英] Why can't a branch name contain the 'space' char?

查看:106
本文介绍了为什么分支名称不能包含“空格"字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过:

  git分支"MyProj/bin/已忽略" 

并收到:

 致命错误:"MyProj/bin/忽略"不是有效的分支名称. 

git-branch 手册页指向 git-check-ref-格式手册页,以获取有效分支名称的实际规则.

可以肯定的是,上述致命错误的原因似乎是因为包含空格字符.

在这个时代,为什么仍然没有从分支名称中排除空格(例如,我希望在古代CVS中使用空格,但要使用Git吗?)

什么可能是有效的技术原因?

解决方案

我不知道您是否会在此问题的底部找到纯粹的技术原因.但是,我可以提供一些倾向于在各种* nix实用程序和文件名处理过程中使用空格的功能,因此,它可以避免意外地做任何错误的事情.毕竟,一个git分支可以简化为存储库中的文件,这避免了处理该文件名中的空格(特别是,分支是.git/refs/heads/中的文件,如注释中所述).

大多数情况下,我认为原因是哲学上的,旨在使事情保持简单.分支名称是人类可读的名称,没有真正的理由使其变得复杂(并且每次哈哈都需要键入两个额外的字符,以调用将每个命令都别名为难以理解的三个字母组合的sysadmin的幽灵).否则称为为什么cd不是chdir"参数.

I tried:

git branch "MyProj/bin/ ignored"

and received:

fatal: 'MyProj/bin/ ignored' is not a valid branch name.

The git-branch man page points to the git-check-ref-format man page to get the actual rules for a valid branch name.

Sure enough, the reason for the above fatal error appears to be the inclusion of a space character.

Any idea why, in this day and age, spaces are still excluded from a branch name (I would have expected it in ancient CVS, for example, but Git?)

What could be valid technical reasons for that?

解决方案

I do not know if you are going to find a pure, technical reason down at the bottom of this. However, I can offer that spaces tend to throw wrenches in all sorts of *nix utilities and filename processing, so it may have been to avoid accidentally doing anything wrong further down the line. After all, a git branch boils down to a file in the repo and this avoids dealing with spaces in that file's name (specifically, a branch is a file in .git/refs/heads/, as mentioned in the comment).

Mostly I would guess the reason is philosophical, and meant to keep things simple. Branch names are human-readable names that have no real reason to be complicated (and require typing two extra chars each time haha, to invoke the ghost of the sysadmin who has aliased every command to an indecipherable three letter combination). Otherwise known as the "why cd is not chdir" argument.

这篇关于为什么分支名称不能包含“空格"字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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