-
Notifications
You must be signed in to change notification settings - Fork 79
[git] Submodules
WIP documenting steps to introduce submodules in wrye-bash.
That's an elaboration of Convert a git folder to a submodule retrospectively? stackoverflow answer.
First of all - if we want to convert a subfolder to a submodule we have to clone the repo:
$ git --version
git version 2.6.1.windows.1
$ git clone /c/Dropbox/eclipse_workspaces/python/wrye-bash compiled
Cloning into 'compiled'...
done.
$ cd compiled
$ git remote -v
origin C:/Dropbox/eclipse_workspaces/python/wrye-bash (fetch)
origin C:/Dropbox/eclipse_workspaces/python/wrye-bash (push)
$ git remote rm origin
This deleted all my remote branches too and since when I cloned I had utumno-wip checked out that's the only one that was left. I recreated dev, checked it out, deleted utumno-wip and run git gc.
This increased the compiled/
folder from 380,332,943 to 517,447,494 bytes.
Throwing in the --aggressive
switch reduced that to 504,360,458 bytes (while
making foobar2000 jump like crazy). Third's the charm:
git gc --prune=now
103,653,306 bytes - let me throw git reflog expire --expire=now --all
(same answer) - no real
diff. And let's delete all tags - I had to add
aggressive again to see a reduction - 103,340,621 bytes, unimportant.
All this time I was giving the size of compiled/
- what we care about is compiled/.git
75,081,955
with only the dev reference at
https://github.com/wrye-bash/wrye-bash/commit/df2fcc5f95bc7bc2613a14cb996671f3b82dd2db
MrD@MrsD MINGW64 /c/Dropbox/eclipse_workspaces/python/compiled (dev)
$ git filter-branch --subdirectory-filter 'Mopy/bash/compiled/' --prune-empty -- --all
Rewrite 9e78dad5d177370f947560a6df3fbacde348fec1 (52/52)
Ref 'refs/heads/dev' was rewritten
And now on to remove the filter branch backup -
one way rm -r .git/refs/original
,
another way:
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d.
but from the same page the safest is to just reclone:
MrD@MrsD MINGW64 /c/Dropbox/eclipse_workspaces/python
$ git clone --no-hardlinks /c/Dropbox/eclipse_workspaces/python/compiled comp
Cloning into 'comp'...
done.
$ cd comp
$ git reflog expire --expire=now --all
$ git gc --prune=now --aggressive
The .git folder is at 24,485,155 bytes - so the 52 commits in this repo account for the 33% of the repo. Great.
Remove origin, renamed dev to master and:
git remote add origin git@github.com:wrye-bash/compiled.git
git push -u origin master
(Note: to undo a git filter branch
git fetch . +refs/original/*:*
)
$ git rm -r Mopy/bash/compiled/
rm 'Mopy/bash/compiled/7z.dll'
rm 'Mopy/bash/compiled/7z.exe'
rm 'Mopy/bash/compiled/CBash.dll'
rm 'Mopy/bash/compiled/libbsa32.dll'
rm 'Mopy/bash/compiled/libbsa64.dll'
rm 'Mopy/bash/compiled/loot32.dll'
rm 'Mopy/bash/compiled/lzma.exe'
$ git submodule add git@github.com:wrye-bash/compiled.git Mopy/bash/compiled
Cloning into 'Mopy/bash/compiled'...
remote: Counting objects: 184, done.
remote: Total 184 (delta 0), reused 0 (delta 0), pack-reused 184
Receiving objects: 100% (184/184), 23.33 MiB | 353.00 KiB/s, done.
Resolving deltas: 100% (111/111), done.
Checking connectivity... done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory.
As you see there is a line endings warning. So before adding the submodule tack a
*.gitmodules text eol=lf
line in the .gitattributes file.
Unfortunately github will not include the submodule contents in the zip file - I sent them a support ticket let's see what they say.