How can I convert an already cloned git repository to a shallow repository?
The git repository is downloaded through a script outside of my control so I cannot do a shallow clone.
The reason for doing this is to save disk space. (Yes, I'm really short on disk space so even though a shallow repository doesn't save much, it is needed.)
I already tried
git repack -a -d -f -depth=1
Let's say the earliest commit you want to keep has a SHA1 of
git checkout c0ffee -- .(Now
HEADis still pointing to your new empty branch, but your working tree and index both look like the tree of
git commit -m "Initial commit, copied from c0ffee"
git diff-tree newbranch c0ffeeshould produce no output -- they have the same tree. (Alternatively, you could do
git show -s c0ffee --format=%Tand
git show -s newbranch --format=%Tand they should show the same hash.)
git rebase --onto newbranch c0ffee master
git branch -d newbranch