V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
git
Pro Git
Atlassian Git Tutorial
Pro Git 简体中文翻译
GitX
LudwigWS
V2EX  ›  git

如何转换一个 repo 为另一个 repo 的 submodule?

  •  
  •   LudwigWS · Sep 26, 2019 · 4028 views
    This topic created in 2417 days ago, the information mentioned may be changed or developed.
    repoA
    repoB
    

    repoA, repoB 都是 Git 仓库。

    想转换为一下结构

    repoA
      repoB
    
    mv repoB repoA
    git submodule add ./repoB/ repoB
    # 'repoB' already exists in the index
    git submodule add -- https://github.com/[repoB] repoB
    # 'repoB' already exists in the index
    

    求大神指点啊。

    7 replies    2019-09-27 05:55:10 +08:00
    compilerhero
        2
    compilerhero  
       Sep 26, 2019
    你不应该把 repoB 移动到 repoA 中, 而是应该直接在 repoB 里需要 repoA 的地方添加 submodule. 一个 submodule 实际上是对另一个 repository 的引用.
    LudwigWS
        3
    LudwigWS  
    OP
       Sep 26, 2019
    @compilerhero
    @yzlnew
    因为本地我已经有这两个仓库了。如果删了 repoB,再执行 `git submodule add` 我想是可以的,但是这会从远程进行 `clone`。

    我想是否有方法在本地就进行 repo 到 submodule 的结构转换。
    compilerhero
        4
    compilerhero  
       Sep 26, 2019
    @LudwigWS 可以的. 添加 submodule 时和克隆时引用源 repository 的方式是一样的. 如果你有一个本地的 repoB 副本, 只要使用指向它的路径就可以, 比如 `git submodule add D:\work\repoB\.git repoB` (我觉得这么做并不好). 你添加的 submodules 都会出现在 .gitmodules 文件里.
    LudwigWS
        5
    LudwigWS  
    OP
       Sep 26, 2019
    @compilerhero 但是我不想指向本地的地址。😅。太难了,我还是删了重新克隆观察一下。
    IMCA1024
        6
    IMCA1024  
       Sep 26, 2019
    subtree?
    jtnwm
        7
    jtnwm  
       Sep 27, 2019
    在 add 的时候添加 --reference 参数指向本地 repoB,会使用本地 repoB 中已有的对象。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3763 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 124ms · UTC 04:46 · PVG 12:46 · LAX 21:46 · JFK 00:46
    ♥ Do have faith in what you're doing.