GIT - 结帐到分支名称以“<”符号开头
GIT - checkout to branch name starts with '<' symbol
我创建了一个名为 <title>-changes
的分支:
git checkout -b <title>-changes
并在该分支上进行了提交。后来我结帐到 another-branch
开始处理 another-branch
。现在我想结帐到以前的分支 (<title>-changes
) 但我现在不能这样做:
git checkout <title>-changes
我知道这是一个简单的问题,但无法破解。我试过了:
git checkout \<title>-changes
git checkout /<title>-changes
git checkout '<title>-changes'
但运气不好。出现如下错误:
$error: pathspec '<title' did not match any file(s) known to git.
$bash: title: No such file or directory
$error: pathspec '<title>-change-pdp ' did not match any file(s) known to git.
您必须同时转义 <
和 >
,因为 bash 将它们视为特殊符号。
为了做到这一点,在每一个前面加上反斜杠 \
:
git checkout \<title\>-changes
这就是我所做的测试,它奏效了。
mkdir test
cd test/
git init
git branch \<title\>-changes
touch empty
git add empty
git commit -m "Added empty file"
git branch \<title\>-changes
git checkout \<title\>-changes
touch second
git add second
git commit -m "Added second empty file"
git checkout -b another-branch
touch third
git add third
git commit -m "Added third empty file"
git checkout \<title\>-changes
除了@Ferran Rigual的回答之外还有另一种解决方案。就像 @Matthieu Moy 说我在分支名称中有一个额外的 space。删除它解决了它 too.ie,
我把git checkout '<title>-changes '
改成了git checkout '<title>-changes'
郑重声明:git checkout '<title>-changes' --
也有效。但我不知道 --
在命令中有任何重要性,因为删除它没有任何区别。
我创建了一个名为 <title>-changes
的分支:
git checkout -b <title>-changes
并在该分支上进行了提交。后来我结帐到 another-branch
开始处理 another-branch
。现在我想结帐到以前的分支 (<title>-changes
) 但我现在不能这样做:
git checkout <title>-changes
我知道这是一个简单的问题,但无法破解。我试过了:
git checkout \<title>-changes
git checkout /<title>-changes
git checkout '<title>-changes'
但运气不好。出现如下错误:
$error: pathspec '<title' did not match any file(s) known to git.
$bash: title: No such file or directory
$error: pathspec '<title>-change-pdp ' did not match any file(s) known to git.
您必须同时转义 <
和 >
,因为 bash 将它们视为特殊符号。
为了做到这一点,在每一个前面加上反斜杠 \
:
git checkout \<title\>-changes
这就是我所做的测试,它奏效了。
mkdir test
cd test/
git init
git branch \<title\>-changes
touch empty
git add empty
git commit -m "Added empty file"
git branch \<title\>-changes
git checkout \<title\>-changes
touch second
git add second
git commit -m "Added second empty file"
git checkout -b another-branch
touch third
git add third
git commit -m "Added third empty file"
git checkout \<title\>-changes
除了@Ferran Rigual的回答之外还有另一种解决方案。就像 @Matthieu Moy 说我在分支名称中有一个额外的 space。删除它解决了它 too.ie,
我把git checkout '<title>-changes '
改成了git checkout '<title>-changes'
郑重声明:git checkout '<title>-changes' --
也有效。但我不知道 --
在命令中有任何重要性,因为删除它没有任何区别。