1

I dont know how to do it so I would like to ask you. In git repo(gitlab) I got 5 commits: A->B->C->D->E and I pushed always a file/files contains 20MB Now Repo is a bit too big. I want to remove commits and FILE from these commits B,C,D. What shoul I do? I have already done:

git checkout <hash-A>
git cherry-pick <hash-E>
git branch -f master
git checkout master
git push -f origin master

and

git rebase -i <hash-A>
git push -f

After that commits are deleted but Repo have the same size as before. Is there any option to remove commits AND size Repo as well?

user1654358
  • 57
  • 2
  • 8
  • The key is to find the big files that the repository has tracked, and then remove the unnecessary ones from the history. See https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository. – ElpieKay Feb 21 '20 at 06:42
  • Does this answer your question? [How to remove/delete a large file from commit history in Git repository?](https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository) – kowsky Feb 21 '20 at 07:49
  • Note that you already constructed a new history, where `master` selects the copy of commit `E` you made atop commit `A`. The extra commits—the original `B-C-D-E` chain—remain in the repository for some time, because Git wants to let you get them back, if you want them. It is hard to throw them out! The easiest way to throw them out is to clone the repository again: the new clone doesn't copy the unreachable commits. – torek Feb 21 '20 at 08:25
  • The alternative is to wait patiently. Unreachable commits, including in this case the `B-C-D-E` chain, remain obtainable for 30 days by default, remembered in the *reflogs*. After 30 days, running `git gc` manually will expire the old reflogs, then shrink the repository database by throwing out the commits. You can make this all happen earlier using various flags, but making it happen sooner than *14* days is the hardest of all of these. – torek Feb 21 '20 at 08:27
  • To make *that* happen, see the notes near the end of [the `git filter-branch` documentation](https://git-scm.com/docs/git-filter-branch). (Search for the CHECKLIST; the documentation has recently grown longer.) – torek Feb 21 '20 at 08:28

0 Answers0