简体   繁体   English

如何将 Git 子模块移动到子目录?

[英]How to move Git submodule to sub-directory?

guys, I just used submodule to organize some Git repos, here's the address: repos伙计们,我只是用 submodule 组织了一些 Git repos,地址在这里: repos

I want to move all the submodule into a new directory called repos, for examples, jquery -> repos/jquery.我想将所有子模块移动到一个名为 repos 的新目录中,例如 jquery -> repos/jquery。

I change the .gitmodules file, but seems it doesn't work.我更改了.gitmodules文件,但似乎它不起作用。 What should I do?我应该怎么办?

Since git 1.8.5,从 git 1.8.5 开始,

git mv old/submod new/submod 

works as expected and does all the plumbing for you.按预期工作并为您完成所有管道工作。 You might want to use git 1.9.3 or newer, because it includes fixes for submodule moving.您可能想要使用 git 1.9.3 或更高版本,因为它包含子模块移动的修复。

Credits: Mike Lowerey from comment below致谢:来自下方评论的 Mike Lowerey

Original answer原始答案

Had the same problem just the moment ago and ended up deleting the submodule reference (as outlined in this article ) and recreating it where i wanted it to go.刚才遇到了同样的问题,最后删除了子模块引用(如本文所述)并在我希望它去的地方重新创建它。

To follow your example of moving submodule jquery into repos/jquery按照您将子模块jquery移动到repos/jquery的示例

  1. Delete the (typically three lines) submodule reference from .gitmodules ..gitmodules中删除(通常是三行)子模块引用。
  2. Check .git/config for references to the submodule and remove them, if existent检查.git/config以获取对子模块的引用并删除它们(如果存在)
  3. do git rm --cached jquery to cut the submodule reference out of the repository执行git rm --cached jquery将子模块引用从存储库中删除
  4. remove the old submodule folder删除旧的子模块文件夹
  5. recreate you submodule reference (as you possibly did before) with git submodule add git://github.com/jquery/jquery.git repos/jquery使用git submodule add git://github.com/jquery/jquery.git repos/jquery重新创建您的子模块引用(就像您以前可能做的那样)

In case your submodule was set to specific tag, respectively commit (which you'll surely have in a stable project) you will have set it again.如果您的子模块设置为特定标签,分别提交(您肯定会在一个稳定的项目中拥有),您将再次设置它。

Due to this complex process i am strongly hoping there is (or will be, at least on the git roadmap) a more straightforward way of achieving this.由于这个复杂的过程,我强烈希望有(或将有,至少在 git 路线图上)一种更直接的方法来实现这一目标。 If not, surely some scripts could be fumbled together to do this quicker...如果不是,那么肯定可以将一些脚本组合在一起以更快地完成此操作...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM