GIT - 结帐到分支名称以“<”符号开头

Asi*_*K T 5 git git-checkout git-branch

我创建了一个名为的分支 <title>-changes

git checkout -b <title>-changes并在该分支上进行了提交。后来我结帐another-branch开始工作another-branch。现在我想结帐到上一个分支 ( <title>-changes) 但我现在无法通过以下方式执行此操作:

git checkout <title>-changes
Run Code Online (Sandbox Code Playgroud)

我知道这是一个简单的问题,但无法破解。我试过:

git checkout \<title>-changes
git checkout /<title>-changes
git checkout '<title>-changes'
Run Code Online (Sandbox Code Playgroud)

但没有运气。得到如下错误:

$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.
Run Code Online (Sandbox Code Playgroud)

小智 5

您必须同时转义两者<>因为 bash 将它们视为特殊符号。

为了做到这一点,在\它们每个前面加上反斜杠:

git checkout \<title\>-changes
Run Code Online (Sandbox Code Playgroud)

这就是我为测试它所做的,并且它奏效了。

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
Run Code Online (Sandbox Code Playgroud)