美文网首页
使用submodule出现的问题

使用submodule出现的问题

作者: 一个想学仙术的菜鸟仔 | 来源:发表于2020-12-15 15:36 被阅读0次

使用需求

存在一套公共的使用库,被很多其它项目使用,又或者很多APP使用的H5页面需要挂到PC项目静态文件中,单纯的代码放到PC项目下,维护又需要拉取整个PC项目修改后进行提交,很不友好,这时候submodule就可以很友好的解决这些问题!

开始

使用

git clone https://github.com/masters.git   //拉取主线
git submodule add https://github.com/public.git  public// 在主线库中添加submodule  

通过以上两步,主线根目录下会出现.gitmodules,是配置文件(有多个子模块,则此文件中将有多个条目),用于存储项目的URL和您将其放入其中的本地子目录之间的映射:

[submodule "public"]
    path = public
    url = https://github.com/public.git

主线目录下查看.git文件(如果隐藏,勾选查看隐藏文件),文件中有一个config文件也会有对应的配置

  • (以上)两个地方会出现对应配置

初始化

克隆一个包含子仓库的仓库目录,并不会clone下子仓库的文件,只是会克隆下.gitmodule描述文件,需要进一步克隆子仓库文件。

cd masters
git submodule init
git submodule update

或者用一行命令
cd masters
git submodule update --init --recursive

此时子目录在一个未命名分支,此时子仓库有改动并没有检测到。

拉取submodule子模块内容

在子仓库,切换到master分支,并git pull最新代码之后,回到主仓库目录,会显示子仓库修改,需要在主仓库提交修改,即修改指定的commit id。

  // public 相当于子模块目录(子模块仓库)直接在当前文件夹下
 git pull

更新

如果在本地修改子仓库,在主仓库 git status会显示子仓库有修改。

 git status
//信息
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

        modified:   public (new commits, untracked content)

no changes added to commit (use "git add" and/or "git commit -a")

需要现在子仓库提交,然后再到主仓库提交代码。

删除子模块

  • 删除.git/config 文件里的关联 (主线)
  • 删除.gitmodules里的关联
  • rm -rf .git/modules/public (也可手动去删除) .git文件夹下面modules还存在子模块

\color{red}{注意 错误 }
1.手动删除子模块,并提交主线,再一次add子模块出现错误

A git directory for 'submoduleSon' is found locally with remote(s):
  origin        https://github.com/public.git
If you want to reuse this local git directory instead of cloning again from
  https://github.com/public.git
use the '--force' option. If the local git directory is not the correct repo
or you are unsure what this means choose another name with the '--name' option.

出现这样的报错.git/config文件和.gitsubmodule文件存在当前public关联(未删除);
手动再去删除两个文件中的关联也不行;

用 git Base here 窗口
cd .git/modules // 切到.git文件下的modules
ls // 查看目录

目录: C:\工作文件夹\测试\submodule\submoduleFather\.git\modules
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/12/15      9:39                submodulePublic
d-----       2020/12/15     14:40               pulic

//发现public还存在(执行删除)
rm -rf public
ls
目录: C:\工作文件夹\测试\submodule\submoduleFather\.git\modules
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2020/12/15      9:39                submodulePublic

//三个地方删除完毕
git submodule add https://github.com/public.git (OKle)

相关文章

  • 使用submodule出现的问题

    使用需求 存在一套公共的使用库,被很多其它项目使用,又或者很多APP使用的H5页面需要挂到PC项目静态文件中,单纯...

  • iOS framework 使用出现 Missing submo

    背景:自己创建的的 framework 在demo 中使用的时候,出现了 Missing submodule 警告...

  • Git submodule 采坑

    Git submodule 采坑 使用git submodule update --init 时遇到错误:erro...

  • LibreSSL SSL_connect: SSL_ERROR_

    这个问题是执行 git submodule 命令时报的错误。网上查的话貌似出现这种问题的原因挺多,没找到合适的。然...

  • 使用Git Submodule管理子模块

    参考链接使用Git Submodule管理子模块 clone Submodule有两种方式 一种是采用递归的方式c...

  • git submodule命令记录

    添加submodule:git submodule add <本地目录> 例如:git submodule ...

  • git submodule的使用

    开发过程中,经常会有一些通用的部分希望抽取出来做成一个公共库来提供给别的工程来使用。现实中,常常有多个这样的库。这...

  • GIT Submodule的使用

    当一个项目需要包含其他支持项目源码时使用的功能,作用是两个项目是独立的,且主项目可以使用另一个支持项目。 添加子项...

  • git submodule的使用

    在初次使用的时候,直接利用sourceTree把项目克隆了下来,发现报错,缺少文件,查看后才知道,原来是项目中集成...

  • git submodule的使用

    开发过程中,经常会有一些通用的部分希望抽取出来做成一个公共库来提供给别的工程来使用,而公共代码库的版本管理是个麻烦...

网友评论

      本文标题:使用submodule出现的问题

      本文链接:https://www.haomeiwen.com/subject/oqvigktx.html