Git 子模块。拉入超级项目的新克隆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7605469/
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
Git Submodules. Pulling into a new clone of the super-project
提问by interstar
OK. So I thought I had this licked ... but now ....
好的。所以我以为我已经舔过了……但现在……
I have a project which includes one small library from GitHub as a submodule. In the original version of that super-project the submodule is working as expected.
我有一个项目,其中包含一个来自 GitHub 的小型库作为子模块。在该超级项目的原始版本中,子模块按预期工作。
However, I just cloned the superproject, did what I thought I should : "git submodule init", got the directory of the submodule to appear, but it's empty.
但是,我只是克隆了超级项目,做了我认为应该做的事情:“git submodule init”,让子模块的目录出现,但它是空的。
If I now try to do
如果我现在尝试做
git submodule update
I get
我得到
fatal: Needed a single revision
Unable to find current revision in submodule path 'external_libraries/BEACHhtml'
If I try
如果我尝试
git submodule foreach git pull
I get
我得到
Entering 'external_libraries/BEACHhtml'
fatal: Where do you want to fetch from today?
Stopping at 'external_libraries/BEACHhtml'; script returned non-zero status.
In my .git/config, I have this :
在我的 .git/config 中,我有这个:
[submodule "external_libraries/BEACHhtml"]
url = [email protected]:interstar/BEACHhtml.git
In my .gitmodules I have this :
在我的 .gitmodules 我有这个:
[submodule "external_libraries/BEACHhtml"]
path = external_libraries/BEACHhtml
url = [email protected]:interstar/BEACHhtml.git
Anyone got an idea what's missing?
任何人都知道缺少什么?
回答by Han He
It seems that now (in 2019) installing latest GIT clientcould solve the problem according to comments below. This should be the best solution for now.
根据下面的评论,现在(2019 年)安装最新的 GIT 客户端似乎可以解决问题。这应该是目前最好的解决方案。
I have the same problem as you. This is a bug in git: http://git.661346.n2.nabble.com/BUG-git-submodule-update-is-not-fail-safe-td7574168.html
我和你有同样的问题。这是 git 中的一个错误:http: //git.661346.n2.nabble.com/BUG-git-submodule-update-is-not-fail-safe-td7574168.html
In short, for your problem, try:
简而言之,对于您的问题,请尝试:
# rm -rf external_libraries/BEACHhtml
# git submodule update
It seems there is something wrong with the previous checkout folder, remove it, and update again solves the problem.
之前的结帐文件夹似乎有问题,将其删除,然后再次更新即可解决问题。
回答by epatel
I had this problem (flaky network so I got dropped submodule checkout like this) and I solved it by making this script (named it git-submodule-fix
so I could run it as git submodule-fix
)
我遇到了这个问题(不稳定的网络,所以我像这样删除了子模块结帐),我通过制作这个脚本来解决它(命名它git-submodule-fix
以便我可以将它运行为git submodule-fix
)
#!/bin/bash
for arg
do
echo $arg
find . -name "`basename $arg`" | grep "$arg$" | xargs rm -fr
done
If you get this i.e. from a git submodule update
如果你从一个 git submodule update
fatal: Needed a single revision
Unable to find current revision in submodule path 'some/submodule/path'
do
做
git submodule-fix some/submodule/path
git submodule update
回答by Lu55
Solved by deleting 2 directories and refetching submodule:
通过删除 2 个目录并重新获取子模块来解决:
- Go to
external_libraries/BEACHhtml
and look into.git
file. It's content should be something likegitdir: ../../.git/modules/external_libraries/BEACHhtml
- Delete both
external_libraries/BEACHhtml
and.git/modules/external_libraries/BEACHhtml
directories.
- 转到
external_libraries/BEACHhtml
并查看.git
文件。它的内容应该是这样的gitdir: ../../.git/modules/external_libraries/BEACHhtml
- 删除
external_libraries/BEACHhtml
和.git/modules/external_libraries/BEACHhtml
目录。
From now on git submodule update
runs without errors.
从现在开始git submodule update
运行没有错误。
回答by vehsakul
If you are reading in 2019 or later, just update the git client. Worked for me.
如果您在 2019 年或以后阅读,只需更新 git 客户端。对我来说有效。
回答by Adam Dymitruk
use a diff tool to compare the original clone that's working and this one. Also, what does git submodule
output. Ensure you are pointing to the same branch in each repo before you do.
使用差异工具来比较正在工作的原始克隆和这个。还有,git submodule
输出什么。在你这样做之前,确保你指向每个 repo 中的同一个分支。
I'm suspecting that you've switched to a branch or older revision where the submodule was not defined.
我怀疑您已切换到未定义子模块的分支或旧版本。
hope this helps
希望这可以帮助
回答by David Lukac
I had the same issue with a submodule on a project. When I tried to clone the submodule separately it worked well.
我对项目中的子模块有同样的问题。当我尝试单独克隆子模块时,它运行良好。
I've tried all of the answers above, but without success (git submodule update, ..., removing the submodule folders, ...).
我已经尝试了上面的所有答案,但没有成功(git submodule update,...,删除子模块文件夹,...)。
The issue disappeared after update of git (from Git-1.7.11-preview20120710) to latest version (to Git-1.8.1.2-preview20130201) at the time. Strangely my colleagues had even older version, worked without any issues, but they were on Mac. I'm on Win7 64bit.
当时将 git(从 Git-1.7.11-preview20120710)更新到最新版本(到 Git-1.8.1.2-preview20130201)后,问题就消失了。奇怪的是,我的同事有更旧的版本,工作没有任何问题,但他们在 Mac 上。我在Win7 64位。