美文网首页
git clone 子模块

git clone 子模块

作者: 小小看护 | 来源:发表于2018-11-29 15:53 被阅读8次

最近在做博客的时候,用到了其他的themes,因为配置,所以需要修改themes里面的代码,这时候有两种做法,一种是直接把代码下到本地,然后将代码直接拷贝项目中,另一种是用git做管理,项目中添加子项目。我先做的是先fork该theme一份,然后git我fork下来的这个项目。具体做法如下

添加子项目

git submodule add [address]

$ git submodule add https://github.com/chaconinc/DbConnector
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.

默认情况下,子模块会将子项目放到一个与仓库同名的目录中,本例中是 “DbConnector”。 如果你想要放到其他地方,那么可以在命令结尾添加一个不同的路径。

自动初始化并更新仓库中的每一个子模块

$ git clone --recursive https://github.com/chaconinc/MainProject
Cloning into 'MainProject'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 14 (delta 1), reused 13 (delta 0)
Unpacking objects: 100% (14/14), done.
Checking connectivity... done.
Submodule 'DbConnector' (https://github.com/chaconinc/DbConnector) registered for path 'DbConnector'
Cloning into 'DbConnector'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
Submodule path 'DbConnector': checked out 'c3f01dc8862123d317dd46284b05b6892c7b29bc'

在包含子模块的项目上工作

如果我们在主项目中提交并推送但并不推送子模块上的改动,其他尝试检出我们修改的人会遇到麻烦,因为他们无法得到依赖的子模块改动。 那些改动只存在于我们本地的拷贝中。
为了确保这不会发生,你可以让 Git 在推送到主项目前检查所有子模块是否已推送。 git push 命令接受可以设置为 “check” 或 “on-demand” 的 --recurse-submodules 参数。 如果任何提交的子模块改动没有推送那么 “check” 选项会直接使 push 操作失败。

$ git push --recurse-submodules=check
The following submodule paths contain changes that can
not be found on any remote:
  DbConnector

Please try

    git push --recurse-submodules=on-demand

or cd to the path and use

    git push

to push them to a remote.

如你所见,它也给我们了一些有用的建议,指导接下来该如何做。 最简单的选项是进入每一个子模块中然后手动推送到远程仓库,确保它们能被外部访问到,之后再次尝试这次推送。

另一个选项是使用 “on-demand” 值,它会尝试为你这样做。

$ git push --recurse-submodules=on-demand
Pushing submodule 'DbConnector'
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (9/9), 917 bytes | 0 bytes/s, done.
Total 9 (delta 3), reused 0 (delta 0)
To https://github.com/chaconinc/DbConnector
   c75e92a..82d2ad3  stable -> stable
Counting objects: 2, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 266 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
To https://github.com/chaconinc/MainProject
   3d6d338..9a377d1  master -> master

如你所见,Git 进入到 DbConnector 模块中然后在推送主项目前推送了它

参考
git clone 子模块(module)
git子模块

相关文章

  • CentOS7 minimal ovirt ovirt-engi

    clone aaa (添加用户(登录)密码的模块) cd /home/coretek/git/git clone ...

  • Git中使用另一个Git

    git clone --recursive git@xxxxgit 这个命令会自动下载他的子模块仓库

  • git clone 子模块

    最近在做博客的时候,用到了其他的themes,因为配置,所以需要修改themes里面的代码,这时候有两种做法,一种...

  • git clone 子模块

    工作开发场景: 使用gitlab进行版本控制开发工作,对git的使用并不是知道的很多,第一次把项目整个gitclo...

  • 日常工作中git命令

    日常 从仓库中clone代码下来 提交代码git add .git commit -m '添加系统管理模块'git...

  • Git Bash使用随记

    clone 代码 git clone git@xxxxxx默认master分支 clone 指定分支代码 git ...

  • git基础操作

    基本: 从master分支clone git clone地址 从指定分支clone git clone -b 远程...

  • github笔记三:完整克隆包括子模块

    1。克隆的时候可以带上参数--recursive,这样会迭代克隆子模块git clone --recursive ...

  • Git常用命令(二)

    1、git clone 功能:克隆git仓。 格式:git clone url 用法: clone完成后,已经存在...

  • Git常用命令

    git clonegit clone git clone ssh://git@xxx.xxx.git克隆远程到本地...

网友评论

      本文标题:git clone 子模块

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