Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git remove history commit

Tags:

git

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?

like image 356
paweb Avatar asked Oct 26 '12 17:10

paweb


1 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.

like image 163
Jeff Bowman Avatar answered Sep 23 '22 07:09

Jeff Bowman