I have a git repository with about 1 year of development history, and it is already 37GB. How can I minimize the size in a way where I will delete the old history? That is, I only need the history that covers the last 2 months, others can be removed.
Asked
Active
Viewed 2,078 times
2
-
How large is the `.git` directory? – Himanshu Mishra Jul 15 '15 at 07:02
-
@HimanshuMishra Hello Sir. The .git directory is about 35G. – rkevx21 Jul 15 '15 at 07:04
-
237G?! I think you have added the executables, movies, photos... IMHO, it is a bad practice, you shall add just the files you need (for test, maybe one or 2 multimedia files) – sop Jul 15 '15 at 07:07
-
Yes, I think that too. It's very rare that your piece of code comprises of 35GB. 1 GB is rare. Have you accidentally commited some large file which is not required? You can also sort the files with size and see are there unnecessary files on the top? – Himanshu Mishra Jul 15 '15 at 07:10
-
@sop yes, it is 37G , since my repository is database tables – rkevx21 Jul 15 '15 at 07:13
-
@HimanshuMishra yes, it is 37G , since my repository is database tables – rkevx21 Jul 15 '15 at 07:14
-
1Does [this](http://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) help? – Himanshu Mishra Jul 15 '15 at 07:17
1 Answers
1
The three main options are:
- removing large files from the history (with, for instance, BFG)
- split a repo subfolder into its own repo
- split a repo history (starting with a new repo from HEAD of new repo, keeping the old one for archive).
On the last point, see "How do I remove the old history from a git repository?", using a script like this one (with the SHA1 of the commit from 2 months ago, as a parameter)
#!/bin/bash
git checkout --orphan temp $1
git commit -m "Truncated history"
git rebase --onto temp $1 master
git branch -D temp
# The following 2 commands are optional - they keep your git repo in good shape.
git prune --progress # delete all the objects w/o references
git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos
Since it rewrites the history, you will need a git push --force
.
Since the OP is pushing to git.assembla.com
(see discussion), this issue clearly states
You need to enable the
--force
option.
This is done from the Git repository Settings tab. You need to be an 'Owner' on the space to see the settings tab.
-
I save the shell script as git-remove-history.sh, how can I execute it sir ? bash git-remove-history.sh ? – rkevx21 Jul 15 '15 at 07:40
-
@rkevx21 what version of Git are you using. What OS (Windows, Linux, Mac) are you using (at which version) – VonC Jul 15 '15 at 07:41
-
@rkevx21 What version of Linux (type `uname -a`) and with what version of Git? (type `git --version`) – VonC Jul 15 '15 at 07:44
-
Linux rkevx21 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux – rkevx21 Jul 15 '15 at 07:45
-
1@rkevx21 Ok. A simple `./git-remove-history.sh
` should be enoough (make sure you have your repo backed up first, or simply available in a Git repo hosting server somewhere before doing that). Replace ` – VonC Jul 15 '15 at 07:47` with the SHA1 of the commit from which you want to start your history (the one commit which is two months old) -
-
@rkevx21 the commit id of the commit from which you want to keep the history. – VonC Jul 15 '15 at 08:02
-
-
@rkevx21 the master should reflect the new history (a git log should only show the last commits) – VonC Jul 15 '15 at 08:24
-
sir , when I run the script, it works, but my problem now is how can I push it to the repository, since it will give you a message to pull first before I can push. – rkevx21 Jul 16 '15 at 03:45
-
Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83378/discussion-between-rkevx21-and-vonc). – rkevx21 Jul 16 '15 at 03:45
-
@rke It rewrites the history of the repo, so you need a Git mush --force. – VonC Jul 16 '15 at 03:46