补充 Submodule.

Signed-off-by: lion.chan <cy187lion@sina.com>
This commit is contained in:
lion.chan 2020-08-09 18:47:36 +08:00
parent 3eb8dca84b
commit c5dd955f7d
1 changed files with 59 additions and 3 deletions

View File

@ -94,7 +94,7 @@ git rm --f <file name>
更多的时候,不需要手动创建 git 仓库。git 仓库很可能已经存在于远端服务器或别人的计算机中,这时候我们只需要将其 clone 到本地即可:
```bash
git clone <URL>
git clone <repository url>
```
例如:
@ -111,7 +111,7 @@ git 支持 http、https、ssh 格式的 URL 访问。
```bash
git add .
git commit -s -m "Message"
git commit -s -m <message>
```
如果想对上次提交进行修改,或将本次提交与上次提交合并,可为 commit 增加 amend 参数,如下:
@ -216,7 +216,7 @@ git tag
命令列出当前仓库中的所有标签,创建一个带附注的的标签则可以使用以下命令实现:
```bash
git tag -a <tag name> -m "Message"
git tag -a <tag name> -m <message>
```
还可以使用:
@ -371,6 +371,62 @@ git rebase -i HEAD~n
git format-patch HEAD^
```
## 18. Submodule
### 18.1. 添加 Submodule
在主仓库中:
```bash
git clone <main-repository url>
cd <main-repository>
git submodule add <sub-repository url>
```
这时主仓库的状态会有变化,可通过 commit 和 push 提交上传:
```bash
git commit -sm <message>
git push
```
### 18.2. 在其他地方使用合并后的版本库
```bash
git clone <main-repository url>
cd <main-repository>
git submodule init && git submodule update
```
### 18.3. 更新合并后的版本库
```bash
cd <sub-repository url>
git commit [...]
cd ..
git commit [...]
```
### 18.4. 批量操作
```bash
git submodule foreach <command>
# 例如
git submodule foreach git submodule update
```
### 18.5 如何保持 Submodule 的同步
如果对第三方 Submodule 进行了定制,但是处于某些原因这些修改并不能提交到远程去。那就要先 fork 第三方仓库,然后在 fork 的基础上添加 Submodule。之后自己的修改或第三方有更新都同步到 fork 的仓库上。
### 18.6 删除 Submodule
```bash
git submodule deinit <submodule-name>
# Or before Git 1.7.8
git rm <submodule-name>
```
## 参考资料
[Pro Git](https://git-scm.com/book/zh/v2)