为什么分支名称在开头不能包含'hash'(#)char?

时间:2022-01-28 21:03:20

This one

这个

git checkout -b #1-my-awesome-feature

creates error

造成错误

error: switch `b' requires a value

escaping it with backslash or wrapping it in quotes will work

用反斜杠转义它或用引号括起它会起作用

git checkout -b \#1-my-awesome-feature

but strange enough this

但这很奇怪

git branch #1-my-awesome-feature

will not produce any error and if you check if it is created with

不会产生任何错误,如果你检查是否创建了它

git branch --all

there is no branch.

没有分支。

If hash char is not in the first position of the branch name, branch will be created.

如果散列字符不在分支名称的第一个位置,则将创建分支。

git branch feature-#1

Executing git branch

执行git分支

feature-#1
* master

So my question is how hash (#) char is 'translated' in terminal and why it is not working when it is at first place?

所以我的问题是hash(#)char是如何在终端中“翻译”的,以及为什么它在第一时就不起作用?

Thanks!

谢谢!

1 个解决方案

#1


2  

# means a comment is starting (atleast in a linux shell). So

#表示评论正在开始(至少在linux shell中)。所以

git checkout -b #1-my-awesome-feature

becomes:

变为:

git checkout -b

and throws error that b option requires a value.

并抛出b选项需要值的错误。

Similarly,

同样的,

git branch #1-my-awesome-feature

becomes:

变为:

git branch

and just shows the branches in your repo.

并在您的仓库中显示分支。

Another Example

Example below is taken from https://unix.stackexchange.com/a/190139/232167

以下示例取自https://unix.stackexchange.com/a/190139/232167

echo "The # here does not begin a comment."
echo 'The # here does not begin a comment.'
echo The \# here does not begin a comment.
echo The # here begins a comment.

#1


2  

# means a comment is starting (atleast in a linux shell). So

#表示评论正在开始(至少在linux shell中)。所以

git checkout -b #1-my-awesome-feature

becomes:

变为:

git checkout -b

and throws error that b option requires a value.

并抛出b选项需要值的错误。

Similarly,

同样的,

git branch #1-my-awesome-feature

becomes:

变为:

git branch

and just shows the branches in your repo.

并在您的仓库中显示分支。

Another Example

Example below is taken from https://unix.stackexchange.com/a/190139/232167

以下示例取自https://unix.stackexchange.com/a/190139/232167

echo "The # here does not begin a comment."
echo 'The # here does not begin a comment.'
echo The \# here does not begin a comment.
echo The # here begins a comment.