interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-submodule.adoc

493 lines · 22201 bytes Raw Blame History
1git-submodule(1)
2================
3
4NAME
5----
6git-submodule - Initialize, update or inspect submodules
7
8
9SYNOPSIS
10--------
11[synopsis]
12git submodule [--quiet] [--cached]
13git submodule [--quiet] add [<options>] [--] <repository> [<path>]
14git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
15git submodule [--quiet] init [--] [<path>...]
16git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>...)
17git submodule [--quiet] update [<options>] [--] [<path>...]
18git submodule [--quiet] set-branch [<options>] [--] <path>
19git submodule [--quiet] set-url [--] <path> <newurl>
20git submodule [--quiet] summary [<options>] [--] [<path>...]
21git submodule [--quiet] foreach [--recursive] <command>
22git submodule [--quiet] sync [--recursive] [--] [<path>...]
23git submodule [--quiet] absorbgitdirs [--] [<path>...]
24
25
26DESCRIPTION
27-----------
28Inspects, updates and manages submodules.
29
30For more information about submodules, see linkgit:gitsubmodules[7].
31
32COMMANDS
33--------
34With no arguments, shows the status of existing submodules. Several
35subcommands are available to perform operations on the submodules.
36
37`add [-b <branch>] [-f | --force] [--name <name>] [--reference <repository>] [--ref-storage-format <format>] [--object-storage-format <format>] [--depth <depth>] [--] <repository> [<path>]`::
38 Add the given repository as a submodule at the given path
39 to the changeset to be committed next to the current
40 project: the current project is termed the "superproject".
41+
42_<repository>_ is the URL of the new submodule's `origin` repository.
43This may be either an absolute URL, or (if it begins with `./`
44or `../`), the location relative to the superproject's default remote
45repository (Please note that to specify a repository `foo.git`
46which is located right next to a superproject `bar.git`, you'll
47have to use `../foo.git` instead of `./foo.git` - as one might expect
48when following the rules for relative URLs - because the evaluation
49of relative URLs in Git is identical to that of relative directories).
50+
51The default remote is the remote of the remote-tracking branch
52of the current branch. If no such remote-tracking branch exists or
53the `HEAD` is detached, `origin` is assumed to be the default remote.
54If the superproject doesn't have a default remote configured
55the superproject is its own authoritative upstream and the current
56working directory is used instead.
57+
58The optional argument _<path>_ is the relative location for the cloned
59submodule to exist in the superproject. If _<path>_ is not given, the
60canonical part of the source repository is used (`repo` for
61`/path/to/repo.git` and `foo` for `host.xz:foo/.git`). If _<path>_
62exists and is already a valid Git repository, then it is staged
63for commit without cloning. The _<path>_ is also used as the submodule's
64logical name in its configuration entries unless `--name <name>` is used
65to specify a logical name.
66+
67The given URL is recorded into `.gitmodules` for use by subsequent users
68cloning the superproject. If the URL is given relative to the
69superproject's repository, the presumption is the superproject and
70submodule repositories will be kept together in the same relative
71location, and only the superproject's URL needs to be provided.
72git-submodule will correctly locate the submodule using the relative
73URL in `.gitmodules`.
74+
75If `--ref-storage-format <format>` or its deprecated alias `--ref-format
76<format>` is specified, the ref storage format of the newly cloned submodules
77will be set accordingly.
78+
79If `--object-storage-format <format>` is specified, the object storage format
80of the newly cloned submodules will be set accordingly.
81
82`status [--cached] [--recursive] [--] [<path>...]`::
83 Show the status of the submodules. This will print the SHA-1 of the
84 currently checked out commit for each submodule, along with the
85 submodule path and the output of linkgit:git-describe[1] for the
86 SHA-1. Each SHA-1 will possibly be prefixed with `-` if the submodule is
87 not initialized, `+` if the currently checked out submodule commit
88 does not match the SHA-1 found in the index of the containing
89 repository and `U` if the submodule has merge conflicts.
90+
91If `--cached` is specified, this command will instead print the SHA-1
92recorded in the superproject for each submodule.
93+
94If `--recursive` is specified, this command will recurse into nested
95submodules, and show their status as well.
96+
97If you are only interested in changes of the currently initialized
98submodules with respect to the commit recorded in the index or the `HEAD`,
99linkgit:git-status[1] and linkgit:git-diff[1] will provide that information
100too (and can also report changes to a submodule's work tree).
101
102`init [--] [<path>...]`::
103 Initialize the submodules recorded in the index (which were
104 added and committed elsewhere) by setting `submodule.$name.url`
105 in `.git/config`, using the same setting from `.gitmodules` as
106 a template. If the URL is relative, it will be resolved using
107 the default remote. If there is no default remote, the current
108 repository will be assumed to be upstream.
109+
110Optional _<path>_ arguments limit which submodules will be initialized.
111If no path is specified and submodule.active has been configured, submodules
112configured to be active will be initialized, otherwise all submodules are
113initialized.
114+
115It will also copy the value of `submodule.$name.update`, if present in
116the `.gitmodules` file, to `.git/config`, but (1) this command does not
117alter existing information in `.git/config`, and (2) `submodule.$name.update`
118that is set to a custom command is *not* copied for security reasons.
119+
120You can then customize the submodule clone URLs in `.git/config`
121for your local setup and proceed to `git submodule update`;
122you can also just use `git submodule update --init` without
123the explicit `init` step if you do not intend to customize
124any submodule locations.
125+
126See the add subcommand for the definition of default remote.
127
128`deinit [-f | --force] (--all|[--] <path>...)`::
129 Unregister the given submodules, i.e. remove the whole
130 `submodule.$name` section from .git/config together with their work
131 tree. Further calls to `git submodule update`, `git submodule foreach`
132 and `git submodule sync` will skip any unregistered submodules until
133 they are initialized again, so use this command if you don't want to
134 have a local checkout of the submodule in your working tree anymore.
135+
136When the command is run without pathspec, it errors out,
137instead of deinit-ing everything, to prevent mistakes.
138+
139If `--force` is specified, the submodule's working tree will
140be removed even if it contains local modifications.
141+
142If you really want to remove a submodule from the repository and commit
143that use linkgit:git-rm[1] instead. See linkgit:gitsubmodules[7] for removal
144options.
145
146`update [--init] [--remote] [-N | --no-fetch] [--[no-]recommend-shallow] [-f | --force] [--checkout | --rebase | --merge] [--reference=<repository>] [--ref-storage-format=<format>] [--object-storage-format=<format>] [--depth=<depth>] [--recursive] [--jobs <n>] [--[no-]single-branch] [--filter=<filter-spec>] [--] [<path>...]`::
147+
148--
149Update the registered submodules to match what the superproject
150expects by cloning missing submodules, fetching missing commits
151in submodules and updating the working tree of
152the submodules. The "updating" can be done in several ways depending
153on command line options and the value of `submodule.<name>.update`
154configuration variable. The command line option takes precedence over
155the configuration variable. If neither is given, a `checkout` is performed.
156(note: what is in `.gitmodules` file is irrelevant at this point;
157see `git submodule init` above for how `.gitmodules` is used).
158The `update` procedures supported both from the command line as well as
159through the `submodule.<name>.update` configuration are:
160
161`checkout`;; the commit recorded in the superproject will be
162checked out in the submodule on a detached `HEAD`.
163+
164If `--force` is specified, the submodule will be checked out (using
165`git checkout --force`), even if the commit specified
166in the index of the containing repository already matches the commit
167checked out in the submodule.
168
169`rebase`;; the current branch of the submodule will be rebased
170onto the commit recorded in the superproject.
171
172`merge`;; the commit recorded in the superproject will be merged
173into the current branch in the submodule.
174
175The following update procedures have additional limitations:
176
177`!<custom-command>`;; mechanism for running arbitrary commands with the
178commit ID as an argument. Specifically, if the
179`submodule.<name>.update` configuration variable is set to
180`!<custom-command>`, the object name of the commit recorded in the
181superproject for the submodule is appended to the _<custom-command>_
182string and executed. Note that this mechanism is not supported in
183the `.gitmodules` file or on the command line.
184
185`none`;; the submodule is not updated. This update procedure is not
186allowed on the command line.
187
188If the submodule is not yet initialized, and you just want to use the
189setting as stored in `.gitmodules`, you can automatically initialize the
190submodule with the `--init` option.
191
192If `--recursive` is specified, this command will recurse into the
193registered submodules, and update any nested submodules within.
194
195If `--ref-storage-format <format>` or its deprecated alias `--ref-format
196<format>` is specified, the ref storage format of the newly cloned submodules
197will be set accordingly.
198
199If `--object-storage-format <format>` is specified, the object storage format
200of the newly cloned submodules will be set accordingly.
201
202If `--filter <filter-spec>` is specified, the given partial clone filter will be
203applied to the submodule. See linkgit:git-rev-list[1] for details on filter
204specifications.
205--
206`set-branch (-b|--branch) <branch> [--] <path>`::
207`set-branch (-d|--default) [--] <path>`::
208 Set the default remote tracking branch for the submodule. The
209 `--branch` option allows the remote branch to be specified. The
210 `--default` option removes the `submodule.<name>.branch` configuration
211 key, which causes the tracking branch to default to the remote `HEAD`.
212
213`set-url [--] <path> <newurl>`::
214 Set the URL of the specified submodule to _<newurl>_. Then, it will
215 automatically synchronize the submodule's new remote URL
216 configuration.
217
218`summary [--cached | --files] [(-n|--summary-limit) <n>] [commit] [--] [<path>...]`::
219 Show commit summary between the given commit (defaults to `HEAD`) and
220 working tree/index. For a submodule in question, a series of commits
221 in the submodule between the given super project commit and the
222 index or working tree (switched by `--cached`) are shown. If the option
223 `--files` is given, show the series of commits in the submodule between
224 the index of the super project and the working tree of the submodule
225 (this option doesn't allow to use the `--cached` option or to provide an
226 explicit commit).
227+
228Using the `--submodule=log` option with linkgit:git-diff[1] will provide that
229information too.
230
231`foreach [--recursive] <command>`::
232 Evaluate an arbitrary shell _<command>_ in each checked out submodule.
233 The command has access to the variables `$name`, `$sm_path`, `$displaypath`,
234 `$sha1` and `$toplevel`:
235+
236--
237`$name`;; the name of the relevant submodule section in `.gitmodules`
238`$sm_path`;; the path of the submodule as recorded in the immediate
239 superproject
240`$displaypath`;; the relative path from the
241 current working directory to the submodules root directory
242`$sha1`;; the commit as recorded in the immediate superproject
243`$toplevel`;; the absolute path to the top-level of the immediate superproject.
244--
245+
246Note that to avoid conflicts with `$PATH` on Windows, the `$path`
247variable is now a deprecated synonym of `$sm_path` variable.
248Any submodules defined in the superproject but not checked out are
249ignored by this command. Unless given `--quiet`, foreach prints the name
250of each submodule before evaluating the command.
251If `--recursive` is given, submodules are traversed recursively (i.e.
252the given shell command is evaluated in nested submodules as well).
253A non-zero return from the command in any submodule causes
254the processing to terminate. This can be overridden by adding ++||:++
255to the end of the command.
256+
257As an example, the command below will show the path and currently
258checked out commit for each submodule:
259+
260--------------
261git submodule foreach 'echo $sm_path `git rev-parse HEAD`'
262--------------
263
264`sync [--recursive] [--] [<path>...]`::
265 Synchronize submodules' remote URL configuration setting
266 to the value specified in `.gitmodules`. It will only affect those
267 submodules which already have a URL entry in `.git/config` (that is the
268 case when they are initialized or freshly added). This is useful when
269 submodule URLs change upstream and you need to update your local
270 repositories accordingly.
271+
272`git submodule sync` synchronizes all submodules while
273`git submodule sync -- A` synchronizes submodule `A` only.
274+
275If `--recursive` is specified, this command will recurse into the
276registered submodules, and sync any nested submodules within.
277
278`absorbgitdirs`::
279 If a git directory of a submodule is inside the submodule,
280 move the git directory of the submodule into its superproject's
281 `$GIT_DIR/modules` path and then connect the git directory and
282 its working directory by setting the `core.worktree` and adding
283 a `.git` file pointing to the git directory embedded in the
284 superprojects git directory.
285+
286A repository that was cloned independently and later added as a submodule or
287old setups have the submodules git directory inside the submodule instead of
288embedded into the superprojects git directory.
289+
290This command is recursive by default.
291
292OPTIONS
293-------
294`-q`::
295`--quiet`::
296 Only print error messages.
297
298`--progress`::
299 Report progress status on the standard error stream
300 by default when it is attached to a terminal, unless `-q`
301 is specified. This flag forces progress status even if the
302 standard error stream is not directed to a terminal. It is
303 only valid for `add` and `update` commands.
304
305`--all`::
306 Unregister all submodules in the working tree. This option is only
307 valid for the `deinit` command.
308
309`-b<branch>`::
310`--branch=<branch>`::
311 Branch of repository to add as submodule.
312 The name of the branch is recorded as `submodule.<name>.branch` in
313 `.gitmodules` for `update --remote`. A special value of `.` is used to
314 indicate that the name of the branch in the submodule should be the
315 same name as the current branch in the current repository. If the
316 option is not specified, it defaults to the remote `HEAD`.
317
318`-f`::
319`--force`::
320 Force the command to proceed, even if it would otherwise fail.
321 This option is only valid for `add`, `deinit` and `update` commands.
322`add`;; allow adding an otherwise ignored submodule path.
323This option is also used to bypass a check that the submodule's name
324is not already in use. By default, `git submodule add` will fail if
325the proposed name (which is derived from the path) is already registered
326for another submodule in the repository. Using `--force` allows the command
327to proceed by automatically generating a unique name by appending a number
328to the conflicting name (e.g., if a submodule named 'child' exists, it will
329try 'child1', and so on).
330`deinit`;; the submodule working trees will be removed even
331if they contain local changes.
332`update`;; (only effective with the checkout procedure),
333throw away local changes in submodules when switching to a
334different commit; and always run a checkout operation in the
335submodule, even if the commit listed in the index of the
336containing repository matches the commit checked out in the
337submodule.
338
339`--cached`::
340 Use the index to determine the commit instead of the `HEAD`.
341 This option is only valid for `status` and `summary` commands.
342
343`--files`::
344 Make the `summary` command compare the commit in the index with that in
345 the submodule `HEAD`.
346
347`-n<n>`::
348`--summary-limit=<n>`::
349 Limit the `summary` size (number of commits shown in total) to _<n>_.
350 Giving 0 will disable the summary; a negative number means unlimited
351 (the default). This limit only applies to modified submodules. The
352 size is always limited to 1 for added/deleted/typechanged submodules.
353
354`--remote`::
355 Instead of using the superproject's recorded SHA-1 to update the
356 submodule, use the status of the submodule's remote-tracking branch.
357 This option is only valid for the `update` command. The remote used
358 is branch's remote (`branch.<name>.remote`), defaulting to `origin`.
359 The remote branch used defaults to the remote `HEAD`, but the branch
360 name may be overridden by setting the `submodule.<name>.branch`
361 option in either `.gitmodules` or `.git/config` (with `.git/config`
362 taking precedence).
363+
364This works for any of the supported update procedures (`--checkout`,
365`--rebase`, etc.). The only change is the source of the target SHA-1.
366For example, `submodule update --remote --merge` will merge upstream
367submodule changes into the submodules, while `submodule update
368--merge` will merge superproject gitlink changes into the submodules.
369+
370In order to ensure a current tracking branch state, `update --remote`
371fetches the submodule's remote repository before calculating the
372SHA-1. If you don't want to fetch, you should use `submodule update
373--remote --no-fetch`.
374+
375Use this option to integrate changes from the upstream subproject with
376your submodule's current `HEAD`. Alternatively, you can run `git pull`
377from the submodule, which is equivalent except for the remote branch
378name: `update --remote` uses the default upstream repository and
379`submodule.<name>.branch`, while `git pull` uses the submodule's
380`branch.<name>.merge`. Prefer `submodule.<name>.branch` if you want
381to distribute the default upstream branch with the superproject and
382`branch.<name>.merge` if you want a more native feel while working in
383the submodule itself.
384
385`-N`::
386`--no-fetch`::
387 Don't fetch new objects from the remote site.
388 This option is only valid for the `update` command.
389
390`--checkout`::
391 Checkout the commit recorded in the superproject on a detached `HEAD`
392 in the submodule. This option is only valid for the `update` command.
393 This is the default behavior, the main use of
394 this option is to override `submodule.<name>.update` when set to
395 a value other than `checkout`.
396 If the key `submodule.<name>.update` is either not explicitly set or
397 set to `checkout`, this option is implicit.
398
399`--merge`::
400 Merge the commit recorded in the superproject into the current branch
401 of the submodule. This option is only valid for the `update` command.
402 If this option is given, the submodule's `HEAD` will
403 not be detached. If a merge failure prevents this process, you will
404 have to resolve the resulting conflicts within the submodule with the
405 usual conflict resolution tools.
406 If the key `submodule.<name>.update` is set to `merge`, this option is
407 implicit.
408
409`--rebase`::
410 Rebase the current branch onto the commit recorded in the superproject.
411 This option is only valid for the `update` command. The submodule's `HEAD` will not
412 be detached. If a merge failure prevents this process, you will have
413 to resolve these failures with linkgit:git-rebase[1].
414 If the key `submodule.<name>.update` is set to `rebase`, this option is
415 implicit.
416
417`--init`::
418 Initialize all submodules for which `git submodule init` has not been
419 called so far before updating. This option is only valid for the `update`
420 command.
421
422
423`--name=<name>`::
424 Set the submodule's name to the given string instead of defaulting to its path. _<name>_
425 must be valid as a directory name and may not end with a `/`.
426
427`--reference=<repository>`::
428 Pass the local _<repository>_ as a reference when cloning the submodule.
429 This option is only valid for `add` and `update` commands.
430 These commands sometimes need to clone a remote repository. In this case,
431 this option will be passed to the linkgit:git-clone[1] command.
432+
433NOTE: Do *not* use this option unless you have read the note
434for linkgit:git-clone[1]'s `--reference`, `--shared`, and `--dissociate`
435options carefully.
436
437`--dissociate`::
438 After using a reference repository to clone from, do not rely on it anymore.
439 This option is only valid for `add` and `update` commands.
440 These commands sometimes need to clone a remote repository. In this case,
441 this option will be passed to the linkgit:git-clone[1] command.
442+
443NOTE: See the NOTE above for the `--reference` option.
444
445`--recursive`::
446 Traverse submodules recursively. This option is only valid for `foreach`,
447 `update`, `status` and `sync` commands. The operation is performed not
448 only in the submodules of the current repo, but also
449 in any nested submodules inside those submodules (and so on).
450
451`--depth=<depth>`::
452 Create a 'shallow' clone with a history truncated to the _<depth>_ revisions.
453 This option is valid for `add` and `update` commands. See linkgit:git-clone[1]
454
455`--recommend-shallow`::
456`--no-recommend-shallow`::
457 Recommend or not shallow cloning of submodules.
458 This option is only valid for the `update` command.
459 The initial clone of a submodule will use the recommended
460 `submodule.<name>.shallow` as provided by the `.gitmodules` file
461 by default. To ignore the suggestions use `--no-recommend-shallow`.
462
463`-j<n>`::
464`--jobs=<n>`::
465 Clone new submodules in parallel with _<n>_ jobs.
466 This option is only valid for the `update` command.
467 Defaults to the `submodule.fetchJobs` option.
468
469`--single-branch`::
470`--no-single-branch`::
471 Clone only one branch during update: `HEAD` or one specified by `--branch`.
472 This option is only valid for the `update` command.
473
474`<path>...`::
475 Paths to submodule(s). When specified this will restrict the command
476 to only operate on the submodules found at the specified paths.
477 (This argument is required with `add`).
478
479FILES
480-----
481When initializing submodules, a `.gitmodules` file in the top-level directory
482of the containing repository is used to find the URL of each submodule.
483This file should be formatted in the same way as `$GIT_DIR/config`. The key
484to each submodule URL is `submodule.<name>.url`. See linkgit:gitmodules[5]
485for details.
486
487SEE ALSO
488--------
489linkgit:gitsubmodules[7], linkgit:gitmodules[5].
490
491GIT
492---
493Part of the linkgit:git[1] suite