如果左侧部分存在并且提交也存在,则无法在Git中创建带有斜线的分支

问题描述 投票:1回答:1

我使用带斜线的分支已有一段时间,但突然发现在某些情况下我无法创建它们

$ git init
Initialized empty Git repository in /home/dimskraft/tests/git-slash-branch/.git/

$ git checkout -b my-branch
Switched to a new branch 'my-branch'

$ git status
On branch my-branch

No commits yet

nothing to commit (create/copy files and use "git add" to track)

$ git checkout -b my-branch/sub-branch
Switched to a new branch 'my-branch/sub-branch'

$ touch myfile.txt
$ git add myfile.txt 
$ git commit -m "added myfile.txt"
[my-branch/sub-branch (root-commit) 9be5cc5] added myfile.txt
...

$ git checkout -b my-branch/sub-branch/aaa
fatal: cannot lock ref 'refs/heads/my-branch/sub-branch/aaa': 'refs/heads/my-branch/sub-branch' exists; cannot create 'refs/heads/my-branch/sub-branch/aaa'

$ git status
On branch my-branch/sub-branch
nothing to commit, working tree clean

为什么并且有可能克服?

git
1个回答
0
投票

因为名为a/b/c的分支存储在名为refs/heads/a/b/c的文件中,这意味着refs/heads/a/b是目录。但是,如果还有一个名为a/b的分支,则refs/heads/a/b必须是file

,并存储that
© www.soinside.com 2019 - 2024. All rights reserved.