git 添加git子模块时“你在一个尚未出生的分支上”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11887203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:21:18  来源:igfitidea点击:

"You are on a branch yet to be born" when adding git submodule

gitgit-submodules

提问by matt b

I am attempting to add a few submodules to my .vim/bundlesdirectory, and when I attempt to add this particular repo Git gives me a strange error I've never seen before:

我正在尝试向我的.vim/bundles目录中添加一些子模块,当我尝试添加这个特定的 repo 时,Git 给了我一个我以前从未见过的奇怪错误:

$ git submodule add -f git://github.com/derekwyatt/vim-scala.git .vim/bundle/vim-scala
fatal: You are on a branch yet to be born
Unable to checkout submodule '.vim/bundle/vim-scala'

Any idea what can cause this?

知道什么会导致这种情况吗?

If I clone the same repo to a test directory (not through the submodule command), it works fine, and creates the expected files.

如果我将同一个 repo 克隆到测试目录(不是通过 submodule 命令),它可以正常工作,并创建预期的文件。

回答by lisachenko

To fix that error, you should delete the folder with the same path to the submodule inside .git/modules/directory. This error can occurs when url was incorrect for submodule for the first-time when submodule was added.

要修复该错误,您应该删除与子模块内部.git/modules/目录具有相同路径的文件夹。当第一次添加子模块时子模块的 url 不正确时,可能会发生此错误。

回答by Useless

You need to add a submodule insidean existing repo, that repo needs to be in a state to add & commit the submodule link, andthe submodule repo itself must have a commit to check out.

您需要现有存储库中添加一个子模块,该存储库需要处于添加和提交子模块链接的状态,并且子模块存储库本身必须有一个提交才能签出。

Now, the submodule repo itself must be ok if you can create a regular clone elsewhere. However, it looks like submodule addcomplains if the repo is empty while clone does not. This guysuggests this is fixable by just running the same submodule addcommand again.

现在,如果您可以在其他地方创建常规克隆,则子模块 repo 本身必须没问题。但是,submodule add如果 repo 为空而 clone 则为空,则它看起来像是在抱怨。这家伙建议只需submodule add再次运行相同的命令即可解决此问题。

If the inner repo is notempty, check the repo you want to containthe submodule. Change to the same directory where you ran git submodule add, and run git status, and git branchto verify that your containing repo has at least one branch created and isn't in a weird state.

如果内部 repo不为空,请检查要包含子模块的 repo 。切换到您运行git submodule add和运行的同一目录git status,并git branch验证您的包含存储库是否至少创建了一个分支并且未处于异常状态。

回答by k4nar

This error can happen if you are adding a submodule which doesn't have a masterbranch. If you want to use another branch when adding the submodule (developfor instance), you can use the following command:

如果您要添加没有master分支的子模块,则可能会发生此错误。如果要在添加子模块时使用另一个分支(develop例如),可以使用以下命令:

git submodule add -b <branch> <repository>

回答by John McFarlane

As alluded to by @drew-noakes, this can be caused by attempting to add a submodule using a directory name that is listed in your .gitignorefile.

正如@drew-noakes 所暗示的,这可能是由于尝试使用.gitignore文件中列出的目录名称添加子模块造成的。