Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update git submodules shallowly with the '--depth' option

git submodule update has supported the --depth option as described in this answer.

But still we can't easily determine the depth value, which would probably make git unable to find the intended revision of a submodule.

Is there a true solution for updating submodules shallowly?

like image 386
Bohr Avatar asked Mar 27 '14 02:03

Bohr


1 Answers

So I think the exact depth would still be a myth, which is the only and must be resolved concern of the question

While there is indeed no "exact depth", you can still record a "depth recommendation" with git 2.9.x+ (Q3 2016).

See commit abed000, commit 37f52e9 (26 May 2016) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit 3807098, 20 Jun 2016)

submodule update: learn --[no-]recommend-shallow option

An upstream project can make a recommendation to shallowly clone some submodules in the .gitmodules file it ships.

Sometimes the history of a submodule is not considered important by the projects upstream.
To make it easier for downstream users, allow a boolean field 'submodule.<name>.shallow' in .gitmodules, which can be used to recommend whether upstream considers the history important.

This field is honored in the initial clone by default, it can be ignored by giving the --no-recommend-shallow option.

That way, a simple git submodule update (no additional parameters) will use the recommended depth value, if found.

See also "Git submodule without extra weight" with:

git config -f .gitmodules submodule.<name>.shallow true

g19fanatic proposes in the comments:

quick 1-liner to add shallow=true to all submodules:

git submodule | awk '{print $2}' | \
  xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true'

or, with git submodule foreach:

git submodule foreach 'git config -f .gitmodules submodule.$sm_path.shallow true'
like image 110
VonC Avatar answered Nov 15 '22 23:11

VonC