I have a large repository git over 3 years, I want to delete history of changes that were more than a year ago. Is this possible? Can use git rebase but how?
-
Git is made for saving your changes. What is the effect of deleting history? – Sandro Meier Oct 26 '12 at 17:55
-
My history is it's too big, .git dir is bigger than 400 MB, in every clone i must download all this history :( – paweb Oct 26 '12 at 17:59
-
Possible duplicate: [How do I remove the old history from a git repository?](http://stackoverflow.com/questions/4515580/how-do-i-remove-the-old-history-from-a-git-repository) – Jeff Bowman Oct 26 '12 at 19:00
-
1Have you already run a garbage collection: `git gc`? – Olaf Dietsche Oct 26 '12 at 19:31
2 Answers
Investigate the black magic called git replace
in this article from the Pro Git book that uses your exact circumstances as its example. Basically, if you can find a point in history that you want to act as the new root, you can replace it with a commit that has no parents, as if it were created out of thin air. You can even store the original tree on a single machine, making it easy to restore the history if you need it again.
Do note that a problem with git rebase
(and git replace
, for that matter) is that you want to rewrite the entire tree, including branches, so they all point to different commits. This also has the consequence of making it hard for others on your team to merge in their changes, because all of the parents have different SHAs than they had before.

- 90,959
- 16
- 217
- 251
-
1From what I read, the ``git replace`` thingy won't work around the changing-hashes-problem. – Jonas Schäfer Oct 26 '12 at 19:16
-
1
-
1Great! It would also be a huge bug in git if you could replace a whole bunch of history without any change in the hashes. After all, those cryptographic hashes are one of the reasons for using git. – Jonas Schäfer Oct 27 '12 at 10:03
Deleting history probably won't fix your problem. Chances are, at some point in time, a large file was committed to the repository and subsequently removed.
I would take a look at Find files in git repo over x megabytes, that don't exist in HEAD.

- 1
- 1

- 2,635
- 1
- 23
- 27