See how much space you’re using
git gc
Quickly see how much space you’re using:
git count-objects -v
Find the biggest objects/blobs in your database:
git verify-pack -v .git/objects/pack/pack-<hash>.idx | sort -k 3 -n | tail -3
git verify-pack -v .git/objects/pack/pack-747fcb154b4b8f254f203cf383e7157ef6541ee6.idx | sort -k 3 -n | tail -3
You can use this to find your blob’s name
git rev-list --objects --all | grep 7a9eb2fb
See all commits that modified a file.
git log --pretty=oneline --branches -- pathToFile
To remove a file from the specified SHA1 hash, all the way downstream.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch <path-to-file>' -- <sha1-where-the-file-was-first-added>..
git filter-branch --index-filter 'git rm --cached --ignore-unmatch composer.phar' -- 458be400a569db6f115539c2d70e616f6d2a0ace..
Remove any refs to a removed file, then repack the database.
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc
Clone a single branch.
git clone <url> --branch <branchName> --single-branch [folder]
Prepare a sub-directory in a project to be split off as its own new project:
git subtree split -P <sub-directory-to-split-off> -b <new-split-branch-1>
Now create a new directory and initialize it:
mkdir <newRepo> && cd <newRepo> && git init
Now we officially make the new repo by pulling in the split off branch:
git pull <path-to-repo-with-new-split-branch-1> <new-split-branch-1>
You may want to bring the unit test along as well. Just split them off to a new branch like before:
git subtree split -P <sub-directory-to-split-off-test> -b <new-split-branch-1-test>
Add a single branch of another repository under a sub-directory, while retaining its history:
git subtree add --prefix=<dest-directory> <path-to-repo-with-new-split-branch-1-test> <new-split-branch-1-test>