git submodule 子模块应用

经常有这样的事情,当你在一个项目上工作时,你需要在其中使用另外一个项目。也许它是一个第三方开发的库或者是你独立开发和并在多个父项目中使用的。这个场景下一个常见的问题产生了:你想将两个项目单独处理但是又需要在其中一个中使用另外一个。

在Git 中你可以用子模块submodule来管理这些项目,submodule允许你将一个Git 仓库当作另外一个Git 仓库的子目录。这允许你克隆另外一个仓库到你的项目中并且保持你的提交相对独立

在项目中遇到的问题

项目中通过composer安装来自segmentFault的markdown语言解析器hyper-down插件,版本为"joyqi/hyper-down": "@dev"

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing joyqi/hyper-down (dev-master 2fad8f9): Cloning 2fad8f9c61 from cache
Writing lock file
Generating autoload files

用git add composer安装自动生成相应的vendor目录时产生以下报错

$git add vendor/
warning: adding embedded git repository: vendor/joyqi/hyper-down
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> vendor/joyqi/hyper-down
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached vendor/joyqi/hyper-down
hint:
hint: See "git help submodule" for more information.

原因是composer安装插件的时候会clone segmentFault在github代码库中的代码,此处再添加到版本控制就会报版本库已经存在

报错信息提出了解决办法,就是通过添加子模块来进行版本控制

解决步骤

然后可以看到根目录下多了一个.gitmodules的文件:

[submodule "vendor/joyqi/hyper-down"]
    path = vendor/joyqi/hyper-down
    url = https://github.com/SegmentFault/HyperDown.git

执行 git add && git commit && git push

代码库

客户端使用

##### 法一:克隆父项目,再更新子模块

子模块前面有一个-,说明子模块文件还未检入(空文件夹)

初始化模块只需在克隆父项目后运行一次

##### 法二 :递归克隆整个项目

##### 执行完可以看到vendor/joyqi/hyper-down文件夹下已经checkout所有文件了

Responses
  1. 서산출장마사지 Oh my goodness! Impressive article dude! Thank you, However I am going through difficulties with your RSS. I don't know why I am unable to subscribe to it. Is there anybody else having similar RSS problems? Anyone who knows the answer will you kindly respond? Thanx!!안산출장안마 , https://jeonjuaroma.club.

    Reply
  2. 김천출장샵 Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your web site is great, as well as the content!경주출장샵 , https://gangneungswedish.site.

    Reply
  3. In an observational series with 12 patients most of whom had received two prior chemotherapy regimens , one patient had a prolonged partial response and one a near complete response after 13 months. http://bestviagrx.com/ In an observational series with 12 patients most of whom had received two prior chemotherapy regimens , one patient had a prolonged partial response and one a near complete response after 13 months.

    Reply
  4. Pretty great post. I just stumbled upon your weblog and wanted to say that I have really loved surfing around your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

    Reply
  5. Viagra http://hitrxmenvia.com/ generic viagra cost

    Reply
  6. п»ї Биткойн нужен, а фермы нет? Установите CryptoTab, первый в мире браузер со встроенной функцией майнинга. Надежный, удобный и простой, CryptoTab Browser добывает для вас BTC в фоновом режиме. http://bit.ly/2TPy2dj https://cryptotabbrowser.com/landing/2/5703690 https://clck.ru/QAzgj =Crypto=

    Reply