0

I am trying to reduce the size of .pack file in git repository. I have removed few uncessary objects in .pack file and pushed back to my developer branch. When I check my activity in gitlab: enter image description here

But My merge request shows as follows: enter image description here

Can someone explain me why merge request shows 49781 additions instead of deletions.

bhr
  • 131
  • 1
  • 10
  • How did you remove the unnecessary objects? – krisz Apr 02 '20 at 16:16
  • 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) – krisz Apr 02 '20 at 16:19
  • I have used command git filter-branch -f --index-filter "git rm --cached --ignore-unmatch ****.zip" rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune git push origin --force --all – bhr Apr 02 '20 at 16:38

1 Answers1

1

You can't merge rewriting of histories. You have to force push to master.

Master still has all the objects, merging would just add the rewritten commits to it, but not remove anything from its history.

But that still leaves other branches and tags that refer to the old objects and will prevent them from being deleted. You also want to update your tags anyway.

You should redo the filter on all branches and tags by appending --tag-name-filter cat -- --all to the filter command. Refer to the git-filter-branch documentation on how to properly shrink the repository.

git filter-branch <...> --tag-name-filter cat -- --all

rm .git/refs/remotes/origin/HEAD
git push -f origin 'refs/remotes/origin/*:refs/heads/*'
git push -f --tags
git fetch

You need to use the same filter (or one that deletes at least as much or more) so your develop branch won't be completely different from the other branches, or reset develop to the state before you filtered it.

krisz
  • 2,686
  • 2
  • 11
  • 18
  • So if I understand correctly, to reduce .pack size by removing unwanted objects can't be done like as regular file modification 1. create custom branch 2. checkout file 3. do modifciations and push it back to custom branch 4. merge it back master branch. – bhr Apr 02 '20 at 17:03
  • Yes, but you already knew that, that's why you used `git-filter-branch`. – krisz Apr 02 '20 at 17:56
  • Thanks @krisz, I have reduced .pack file size and checked in directly to master branch. I did git push -f --all and git push -f --tags. After that if I clone again my .pack file is same as old one. I am not sure what I am missing, do you have any idea? – bhr Apr 03 '20 at 12:58
  • Does it reduce the size if you run `git gc --prune=now --aggressive` on a fresh clone? – krisz Apr 03 '20 at 13:36
  • after git gc --prune=now --aggressive it's reduced from 706mb to 661mb in fresh clone. But the original size is 89mb from where I have pushed to master branch. – bhr Apr 03 '20 at 13:59
  • Then there are still references to the old objects. For starters, how many commits does this show: `git log --all --max-parents=0`? – krisz Apr 03 '20 at 16:55
  • git log --all --max-parents=0 shows only one commit – bhr Apr 03 '20 at 17:33
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/210890/discussion-between-krisz-and-user3665615). – krisz Apr 03 '20 at 18:37