1

I have a repo with a large number of commits and tags and I want to remove the history older than a certain tag so it that the repo size will be much smaller. How can I do that?

Previous questions do not identify with the objective of removing history older than a certain tag nor offer a concise solution.

solet
  • 19
  • 4
  • possible duplicate of [Git remove history commit](http://stackoverflow.com/questions/13091928/git-remove-history-commit) – sschuberth Aug 10 '15 at 19:07

1 Answers1

0

Instead of truncating the history permanently on the server-side, you could pass --depth to git clone to truncate it on the client side only. To determine the depth / number of commits since a tag you can use git rev-list $tag..HEAD --count.

sschuberth
  • 28,386
  • 6
  • 101
  • 146
  • Thank you @sscuberth. I agree that is not desirable to destructively remove history. Regardless, when it truly no longer matters or you have forked from an upstream where a significant amount of the original history can be pruned away because it has become cruft, I want to know how this can be done properly. Depth must be predetermined before it can be applied. Are there there better ways to do this permanently? – solet Aug 10 '15 at 17:34
  • There already are at least [two](http://stackoverflow.com/a/20152495/1127485) [answers](http://stackoverflow.com/a/13092954/1127485) that seem to cover your use case. Both involve using `rebase` / `replace` and force-pushing, followed by `gc` to prune stale history. – sschuberth Aug 10 '15 at 19:05