git 如何拉一个新的子模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44105166/
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
How to pull a new submodule
提问by Pysis
Tried looking for answers on this site and others: StackOverflow - Easy way pull latest of all submodules
尝试在本网站和其他网站上寻找答案: StackOverflow - 提取所有子模块中最新的简单方法
They all seem to want to talk about if you are controlling them, not if someone else added one, and I just want to pull the additional one into my project without having to stash or backup my changes if I need to delete the folder.
他们似乎都想谈论您是否在控制它们,而不是其他人是否添加了一个,我只想将另一个添加到我的项目中,而无需在需要删除文件夹时隐藏或备份我的更改。
Should I delete the .gitmodules
file, and/or the submodule directories that I have already pulled down with git clone --recursive
?
(StackOverflow - How to git clone
including submodules?)
我应该删除.gitmodules
文件和/或我已经下拉的子模块目录git clone --recursive
吗?(StackOverflow - 如何git clone
包含子模块?)
These commands do not seem to help either:
这些命令似乎也没有帮助:
git submodule update --init --recursive
seems like it did nothing.git submodule update --recursive
nothing.git fetch --recurse-submodules
outputFetching submodule ...
several times.git pull --recurse-submodules
output the same thing, and then saidAlready up-to-date.
after the fetch trial. Strange since in either case my submodules were already downloaded.git clone --recursive ...
Not tried yet.I feel like would overwrite any changes I have made, in the Stash or otherwise.git submodule update --recursive --remote
checked out a new commit SHA for one of the submodules.git submodule update --recursive
checked out a new commit SHA for one of the submodules. Could be the older, original commit level.git submodule status
gives the appropriate SHA, version, and name information for each, while still lacking the one that I want.git submodule foreach git pull origin master
git submodule update
does nothing.
git submodule update --init --recursive
好像什么都没做。git submodule update --recursive
没有。git fetch --recurse-submodules
输出Fetching submodule ...
几次。git pull --recurse-submodules
输出同样的东西,然后Already up-to-date.
在fetch试用后说。奇怪,因为在任何一种情况下我的子模块都已经下载了。git clone --recursive ...
还没试过。我觉得会覆盖我在 Stash 或其他地方所做的任何更改。git submodule update --recursive --remote
为其中一个子模块签出新的提交 SHA。git submodule update --recursive
为其中一个子模块签出新的提交 SHA。可能是较旧的原始提交级别。git submodule status
为每个提供了适当的 SHA、版本和名称信息,同时仍然缺少我想要的信息。git submodule foreach git pull origin master
git submodule update
什么也没做。
I have been double-checking the library directory manually each time to make sure whether the additional submodule appeared or not.
我每次都手动仔细检查库目录,以确保附加子模块是否出现。
I want to avoid performing certain actions, unless they are not destructive to my current repository state containing code changes, and solves my problem, in case it is a command I have mentioned but did not run, or anyone else has another to try.
我想避免执行某些操作,除非它们对我当前包含代码更改的存储库状态没有破坏性,并且解决了我的问题,以防它是我提到但没有运行的命令,或者其他人有另一个要尝试的命令。
I could try some of these with more effort, but I think I want to stop messing with them for now, and since I have not found the answer to this issue after doing some online searching, maybe the hopeful and eventual answer would help others anyway.
我可以更努力地尝试其中的一些,但我想我现在不想再弄乱它们了,而且由于我在进行了一些在线搜索后还没有找到这个问题的答案,也许希望和最终的答案无论如何都会对其他人有所帮助.
Am I suffering from the con mentioned here at all? Software Engineering - Git submodule vs Git clone
我是否患有这里提到的骗局? 软件工程 - Git 子模块与 Git 克隆
More links:
更多链接:
回答by Aaron Walerstein
git submodule update --init local/path/to/submodule/folder
回答by Fabian Fagerholm
You have to do two things:
你必须做两件事:
- Do
git pull
in your main repository which holds the submodules. This will add the new submodule as an empty directory. - Do
git submodule update --recursive --remote
in the main repository. This will pull the latest changes for all submodules, including the new one.
- 不要
git pull
在持有子模块你的主存储库。这会将新的子模块添加为空目录。 - 不要
git submodule update --recursive --remote
在主存储库中。这将拉取所有子模块的最新更改,包括新的。
This works at least in Git 2.13. Also note that if the repositories and submodules are on GitHub, you have to make sure you have access rights to them (if they are private).
这至少在 Git 2.13 中有效。另请注意,如果存储库和子模块在 GitHub 上,您必须确保您有权访问它们(如果它们是私有的)。
回答by Pysis
Best suggestion I have received so far is to run this command:
到目前为止,我收到的最佳建议是运行以下命令:
git submodule add <URL_to_submodule> <local_path_to_place_submodule>
So it looks to be what the other contributor would have done, that I would do again, even though it already exists in the remote.
所以它看起来是其他贡献者会做的,我会再做一次,即使它已经存在于远程中。
I guess this doesn't technically update the .gitmodules
file from the remote's data like what would be expected, but haven't found a way to do that yet.
我想这在技术上并没有.gitmodules
像预期的那样从远程数据更新文件,但还没有找到一种方法来做到这一点。
Credit for the help goes to @pandatrax.
感谢@pandatrax的帮助。
Update
更新
Before trying the add
method, I tried 1 more idea that involved copying the .gitmodules
file from the remote manually and trying any of the update commands, but sadly that approach did not work either. It may have gone differently if I executed the commands in the root, since I was in a subfolder, but I doubt it.
在尝试该add
方法之前,我尝试了另外一个想法,包括.gitmodules
手动从远程复制文件并尝试任何更新命令,但遗憾的是,这种方法也不起作用。如果我在根目录中执行命令,结果可能会有所不同,因为我在子文件夹中,但我对此表示怀疑。
Then I used the add
method, which downloaded the dependency, but the .gitmodules
file showed changes. Once I set-up the GitHub remote and pulled from it after discarding that file, the project seems to be in a better state now, even syncing the commit SHAs for the updated module or 2, either since they matched, or it was overwritten.
然后我使用了add
下载依赖项的方法,但.gitmodules
文件显示更改。一旦我设置了 GitHub 远程并在丢弃该文件后从中拉出,该项目现在似乎处于更好的状态,甚至同步更新模块或 2 的提交 SHA,因为它们匹配或被覆盖。
回答by Lekkie
This should work, as long as the new submodule is in the .gitmodules in remote
只要新的子模块在远程的 .gitmodules 中,这应该有效
git pull --recurse-submodules
git pull --recurse-submodules