# gitmodules
> 原文: [https://git-scm.com/docs/gitmodules](https://git-scm.com/docs/gitmodules)
## 名稱
gitmodules - 定義子模塊屬性
## 概要
$ GIT_WORK_DIR / .gitmodules
## 描述
`.gitmodules`文件位于Git工作樹的頂級目錄中,是一個文本文件,其語法與 [git-config [1]](https://git-scm.com/docs/git-config) 的要求相匹配。
該文件包含每個子模塊的一個子部分,子部分值是子模塊的名稱。該名稱設置為添加子模塊的路徑,除非使用 _git子模塊添加_的`--name`選項進行自定義。每個子模塊部分還包含以下必需的鍵:
```
submodule.<name>.path
```
定義相對于Git工作樹的頂級目錄的路徑,其中預期子模塊將被檢出。路徑名稱不得以`/`結尾。所有子模塊路徑在.gitmodules文件中必須是唯一的。
```
submodule.<name>.url
```
定義可以從中克隆子模塊存儲庫的URL。這可以是準備傳遞給 [git-clone [1]](https://git-scm.com/docs/git-clone) 的絕對URL,或者(如果它以./或../開頭)相對于超級項目的原始存儲庫的位置。
此外,還有許多可選鍵:
```
submodule.<name>.update
```
定義命名子模塊的默認更新過程,即超級項目中“git submodule update”命令如何更新子模塊。這僅由`git submodule init`用于初始化同名的配置變量。這里允許的值是_檢出_, _rebase_ ,_合并_或_無_。有關其含義,請參閱 [git-submodule [1]](https://git-scm.com/docs/git-submodule) 中 _update_ 命令的說明。請注意,出于安全原因,此處有意忽略_!命令_表單。
```
submodule.<name>.branch
```
用于跟蹤上游子模塊中的更新的遠程分支名稱。如果未指定該選項,則默認為 _master_ 。 `.`的特殊值用于指示子模塊中分支的名稱應與當前存儲庫中當前分支的名稱相同。有關詳細信息,請參閱 [git-submodule [1]](https://git-scm.com/docs/git-submodule) 中的`--remote`文檔。
```
submodule.<name>.fetchRecurseSubmodules
```
此選項可用于控制此子模塊的遞歸獲取。如果此選項也存在于超級項目的.git / config中的子模塊條目中,則該設置將覆蓋.gitmodules中的設置。通過使用“git fetch”和“git pull”的“ - [no-] recurse-submodules”選項,可以在命令行上覆蓋這兩個設置。
```
submodule.<name>.ignore
```
定義在什么情況下“git status”和diff系列將子模塊顯示為已修改。支持以下值:
```
all
```
子模塊永遠不會被視為已修改(但仍將顯示在狀態輸出中并在提交時提交)。
```
dirty
```
將忽略對子模塊工作樹的所有更改,僅考慮子模塊的HEAD與其在超級項目中的記錄狀態之間的已提交差異。
```
untracked
```
只有子模塊中未跟蹤的文件才會被忽略。將顯示對跟蹤文件的承諾差異和修改。
```
none
```
不會忽略對子模塊的修改,顯示所有已提交的差異以及對已跟蹤和未跟蹤文件的修改。這是默認選項。
如果此選項也存在于超級項目的.git / config中的子模塊條目中,則該設置將覆蓋.gitmodules中的設置。
可以使用“--ignore-submodule”選項在命令行上覆蓋這兩個設置。 _git子模塊_命令不受此設置的影響。
```
submodule.<name>.shallow
```
設置為true時,除非用戶明確要求非淺層克隆,否則此子模塊的克隆將作為淺層克隆(歷史深度為1)執行。
## 例子
請考慮以下.gitmodules文件:
```
[submodule "libfoo"]
path = include/foo
url = git://foo.com/git/lib.git
```
```
[submodule "libbar"]
path = include/bar
url = git://bar.com/git/lib.git
```
這定義了兩個子模塊,`libfoo`和`libbar`。這些預期將在路徑 _include / foo_ 和 _include / bar_ 中檢出,并且對于這兩個子模塊,指定了可用于克隆子模塊的URL。
## 也可以看看
[git-submodule [1]](https://git-scm.com/docs/git-submodule) [git-config [1]](https://git-scm.com/docs/git-config)
## GIT
部分 [git [1]](https://git-scm.com/docs/git) 套件
- git
- git-config
- git-help
- git-init
- git-clone
- git-add
- git-status
- git-diff
- git-commit
- git-reset
- git-rm
- git-mv
- git-branch
- git-checkout
- git-merge
- git-mergetool
- git-log
- git-stash
- git-tag
- git-worktree
- git-fetch
- git-pull
- git-push
- git-remote
- git-submodule
- git-show
- git-log
- git-shortlog
- git-describe
- git-apply
- git-cherry-pick
- git-rebase
- git-revert
- git-bisect
- git-blame
- git-grep
- gitattributes
- giteveryday
- gitglossary
- githooks
- gitignore
- gitmodules
- gitrevisions
- gittutorial
- gitworkflows
- git-am
- git-format-patch
- git-send-email
- git-request-pull
- git-svn
- git-fast-import
- git-clean
- git-gc
- git-fsck
- git-reflog
- git-filter-branch
- git-instaweb
- git-archive
- git-bundle
- git-daemon
- git-update-server-info
- git-cat-file
- git-check-ignore
- git-checkout-index
- git-commit-tree
- git-count-objects
- git-diff-index
- git-for-each-ref
- git-hash-object
- git-ls-files
- git-merge-base
- git-read-tree
- git-rev-list
- git-rev-parse
- git-show-ref
- git-symbolic-ref
- git-update-index
- git-update-ref
- git-verify-pack
- git-write-tree