gpt4 book ai didi

git - 在 Git 分支名称中使用斜杠字符

转载 作者:行者123 更新时间:2023-12-01 14:33:42 26 4
gpt4 key购买 nike

我很确定我在一个流行的 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

如何在 Git 中创建一个带有斜杠字符的分支?

最佳答案

你确定分支labs不存在(如 this thread )?

You can't have both a file, and a directory with the same name.

You're trying to get git to do basically this:

% 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

You're getting the equivalent of the "cannot create directory" error.
When you have a branch with slashes in it, it gets stored as adirectory hierarchy under .git/refs/heads.



请注意 labs不能是现有分支,如 ddruganovthe comments 中指出:
 git switch -c 19023-commerce/19033-commerce-view 19023-commerce

# Fails with:

fatal: cannot lock ref 'refs/heads/19073-commerce-view/99999-test-branch':
'refs/heads/19073-commerce-view' exists;
cannot create 'refs/heads/19073-commerce-view/99999-test-branch'
如“ git push: refs/heads/my/subbranch exists, cannot create ”中所述:
  • If branch b exists, no branch named b/anything can be created.
  • Likewise, if branch dev/b exists, dev/b/c cannot be created.

This is a git internal limitation.

关于git - 在 Git 分支名称中使用斜杠字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52948581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com