[dev] Git splitting

Thomas Jarosch thomas.jarosch at intra2net.com
Thu Jun 20 07:15:16 UTC 2013


On Wednesday, 19. June 2013 23:25:56 Michael M Slusarz wrote:
> Now that the main portion of the x.1 releases are out the door, time
> to talk about splitting the Git repo.
> 
> (If there was any doubt we need to split, try cloning the Git repo
> from GitHub.  I did it today and it took 3 1/2 minutes.  Ugh)

Forgive my ignorance, won't cloning of all the (small) repositories
also take 3 1/2 minutes or even more?


We splitted up some git repos at work and I made notes
of certain complex git commands. May be they might come in handy:

------------------------------------------------
Filter directory based on a whitelist:
git filter-branch --tag-name-filter cat --index-filter \
    'git ls-files -s |grep -P "\t(DIR1|DIR2)" \
    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all


Rename directories / remove prefixes (in this case source/):
git filter-branch --tag-name-filter cat --index-filter \
    'git ls-files -s | sed "s-\tsource/-\t-" \
    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all


Delete single files or directories:
git filter-branch --tag-name-filter cat --index-filter 'git rm --cached --ignore-unmatch -r -f CVSROOT Attic packages/Attic source/Attic' -- --all


Remove empty commits:
git filter-branch --tag-name-filter cat --commit-filter 'if [ z$1 = z`git rev-parse $3^{tree}` ]; then skip_commit "$@"; else git commit-tree "$@"; fi' "$@" -- --all


Free up space for real:
git for-each-ref --format='%(refname)' refs/original | xargs -i git update-ref -d {}
git reflog expire --expire=0 --all
git repack -a -d
git prune
------------------------------------------------

HTH,
Thomas



More information about the dev mailing list