子模块
Git 子模块允许你将一个 Git 仓库当作另外一个 Git 仓库的子目录。这允许你克隆另外一个仓库到你的项目中并且保持你的提交相对独立。
新增子模块
$ git submodule add https://github.com/theme-next/hexo-theme-next.git <hexo-theme-next>
该命令会自动 clone
远程仓库的到本地,创建 hexo-theme-next 文件夹,同时生成 .gitmodules
文件,来记录子模块信息。
$ git status
On branch hexo-sources
Your branch is up to date with 'origin/hexo-sources'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: ../.gitmodules
new file: hexo-theme-next
$ cat ../.gitmodules
[submodule "themes/hexo-theme-next"]
path = themes/hexo-theme-next
url = https://github.com/theme-next/hexo-theme-next.git
克隆一个带子模块的项目
克隆一个带子模块的项目 将得到了包含子项目的目录,但里面没有文件。必须运行两个命令:
git submodule init
来初始化你的本地配置文件git submodule update
来从那个项目拉取所有数据并检出你上层项目里所列的合适的提交