我使用带斜线的分支已有一段时间,但突然发现在某些情况下我无法创建它们
$ 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
为什么并且有可能克服?
因为名为a/b/c
的分支存储在名为refs/heads/a/b/c
的文件中,这意味着refs/heads/a/b
是目录。但是,如果还有一个名为a/b
的分支,则refs/heads/a/b
必须是file