代码之家  ›  专栏  ›  技术社区  ›  CoDe

Git分支创建问题:“致命:无法锁定ref'refs/heads/”[重复]

  •  1
  • CoDe  · 技术社区  · 6 年前

    我很肯定我在一个流行的Git项目中看到了分支有一个类似“feature/xyz”的模式。

    但是,当我尝试使用斜线字符创建分支时,会得到一个错误:

    $ git branch labs/feature
    error: unable to resolve reference refs/heads/labs/feature: Not a directory
    fatal: Failed to lock ref for update: Not a directory
    

    同样的问题(我最初的尝试):

    $ git checkout -b labs/feature
    

    0 回复  |  直到 15 年前
        1
  •  216
  •   nmr    11 年前

    你确定分支 labs this thread )?

    不能同时拥有文件和同名目录。

    你想让git做的基本上是:

    % cd .git/refs/heads
    % ls -l
    total 0
    -rw-rw-r-- 1 jhe jhe 41 2009-11-14 23:51 labs
    -rw-rw-r-- 1 jhe jhe 41 2009-11-14 23:51 master
    % mkdir labs
    mkdir: cannot create directory 'labs': File exists
    

    您得到的结果相当于“无法创建目录”错误。
    如果分支中有斜线,则将其存储为 目录层次结构 .git/refs/heads .

        2
  •  103
  •   Jakub Narębski adamtaub    15 年前

    可以有层次结构的分支名称(带有斜线的分支名称)。例如,在我的存储库中,我有这样的分支。一个警告是,不能在存储库中同时拥有分支“foo”和分支“foo/bar”。

    您的问题不在于创建名称中带有斜杠的分支。

    $ git branch foo/bar
    error: unable to resolve reference refs/heads/labs/feature: Not a directory
    fatal: Failed to lock ref for update: Not a directory
    

    上面的错误消息是关于“labs/feature”分支,而不是“foo/bar”(除非在复制“n”粘贴时出错,即您编辑了会话的某些部分)。结果是什么 git branch git rev-parse --symbolic-full-name HEAD ?

        3
  •  33
  •   Michael come lately PhiLho    10 年前

    我试过这个:

    git checkout -b features/aName origin/features/aName
    

    features ,我得到了提问者的例外。

    移除分支 特征 解决了这个问题,上面的命令起作用了。

        4
  •  31
  •   flori    9 年前

    在我的情况下,我忘了已经有一个未使用的 labs 分支。删除它解决了问题:

    git branch -d labs
    git checkout -b labs/feature
    

    说明:

    每个 只能是父分支 正常的分支,不是两者都有。这就是为什么树枝 实验室 labs/feature 不能同时存在。

    这种行为的原因是,分支存储在文件系统中,并且在那里也不能有文件 实验室 实验室 在同一水平。

        5
  •  -1
  •   crazyscot    15 年前

    我可能错了,但我认为斜杠只出现在与远程回购相关的分支名称中,例如 origin/master .