I have added few git submodules and they are configured in .gitmodules. I am interested in specific commits of submodules. Hence I commit these commits and the can be seen in git submodule status. Say for
[submodule "pcl"]
path = libs/pcl
url = https://github.com/PointCloudLibrary/pcl.git
the submodule status shows 757e28a75a0c6c0413085a2af070670828a48527
libs/pcl.
This means the above SHA1 will be checked out after running git submodule update --init
However, my problem is that I dont want to entirely clone the submodule pcl, because I am just interested in the commit from 757e28a75a0c6c0413085a2af070670828a48527 onwards. Is there any way to achieve this by writing a depth parameter etc in the .gitmodules file?
I have seen several posts, but most of them suggest to do a git add submodule. Since, I already have done this, is there a way, to edit the .gitmodule file with a depth parameter for each submodules.
git clone --depth 10 --shallow-submodules <repo>
would in my opinion pull 10 commits of the main branch and subsequently the tip of the master branch of all the submodules. Is my understanding correct?
found a work around for the problem, and that might help others.
The goal was to shallow clone submodules. By following the below steps, the size of the project ( including submodules ) reduced from 30 GB to 2 GB. The project consists of lots of submodules that are constantly developed such as opencv, ffmpeg, pcl, mrpt etc.
.gitmodule just consists of the submodule name, path and the url ( hence no fancy config options ), like this
[submodule "pcl"]
path = libs/pcl
url = https://github.com/PointCloudLibrary/pcl.git
So, start with cloning, and then init submodules and finally update submodules.
git clone --depth 10 <repo>
git submodule init
git submodule update --depth 10
In case of error - error: Server does not allow request for unadvertised object SHA, increase the depth for this particular module for example 100.
git submodule update --depth 100 <submodule> # for those modules, whose depth doesnt match. try with different depths.
When successful, continue with default
git submodule update --depth 10
Hope it is helpful for someone and further solutions re most welcome.