1

Suppose I am on commit a which has submodule s1

and somebody added submodule s2 in commit a+1, now I don't want to move to a+1 but fetch(just download) submodule s2.

Is this possible?

my git version is 2.1.4 I can get 2.10.1.windows.1 if required to update

Edit: simple script I tried, it has some problems - .git folder is inside the new cloned submodule rather than in super rep's .git/modules folder - working directory is polluted with the new submodule :|

git diff HEAD origin/master .gitmodules 2>&1 | perl -e '
while(<>)
{
   if(/^\+\s+path = (.+)/)
   {
      my $path = $1;
      my $line = <>;
      if($line=~/^\+\s+url = (.+)/)
      {
         my $url = $1;
         print "$path -> $url\n";
         `git clone "$url" "$path"`
      }
   }
}'
tejas
  • 1,795
  • 1
  • 16
  • 34

1 Answers1

0

Is this possible?

Not exactly: you can show the content of the latest .gitmodule file:

git fetch
git show origin/master:./.gitmodules

That will give you the url of the second submodule s2, but not its SHA1.

If that is enough, you can clone it within your own repo (nested git repo).


If you can upgrade to the latest Git for Windows (2.11 or soon 2.12), I would use the git worktree command:

  • checkout the a+1 commit in a separate worktree (with said git worktree command), and run a git submodule update --init in that separate worktree,
  • make (from your own current repo still at commit 'a') a symbolic link to s2 which is correctly checked out at the right SHA1

That way, you don't move your current repo but still benefit from the actual submodule content s2 from a+1.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So this is a simple script i made for your 1st method, Is anything wrong here? because when i clone s2 the `.git` folder of submodule is inside the submodule not in the super repository's `.git/modules` Edit: putting the script in question as I cant format it here – tejas Feb 20 '17 at 13:39
  • @tejas don't bother with the 1st method: it would not know which exact version of s2 to checkout. Do the 2d method with git worktree: it allows you to have multiple working trees, meaning your current working tree will be untouched (except for the symbolic link, which does exist in Windows as well, with a simple junction: `mklink /J`) – VonC Feb 20 '17 at 13:45
  • I don't really need to checkout s2, was just trying to save the download time when actually checking out/doing submodule update – tejas Feb 20 '17 at 13:49
  • @tejas the download time will be minimal (the git fetch will only download the delta). It is true s2 would be fetched/checked out in full though, unless it is set for a shallow clone. The point is: to get the right s2 content, you need the n+1 commit. – VonC Feb 20 '17 at 13:53
  • @tejas Regarding the first method and your script, why not adding the root folder of the nested repo s2 in your .gitignore? – VonC Feb 20 '17 at 13:54