Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to init a submodule in a tag while keeping the depth at 1

For a normal git repo you can do:

git clone --branch 4.1.1 https://github.com/WordPress/WordPress.git . --depth 1

Which will give a WP repo at tag 4.1.1

For a submodule I did get the below but I can't figure out how to do it for just one tag.

git submodule add --depth 1  https://github.com/WordPress/WordPress.git wp

How do I checkout a submodule to 1 tag at 1 depth?

I don't mind doing a few more commands afterwards but if possible in one command even better.

TLDR: I want a submodule at a tag. Which .git(/module) folder is as small as possible.

like image 282
janw Avatar asked Mar 23 '15 13:03

janw


1 Answers

Considering a submodule might not comes with its tags, you might be tempted to do first (as suggested in "Can git submodule update be made to fetch tags in submodules?"):

git submodule foreach --recursive 'git fetch --tags'

But as I explained in "Does “git fetch --tags” include “git fetch”?", that would not fetch just the tags, but also all the associated commits (since git 1.9.0, February 2014)

Instead, you can go in the submodule, and fetch that tag content with a depth of 1:

git fetch --depth=1 origin refs/tags/<tag>:refs/tags/<tag>
git checkout <tag>
like image 75
VonC Avatar answered Oct 21 '22 22:10

VonC