newren / git-filter-repo

Quickly rewrite git repository history (filter-branch replacement)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

changes in the local .git/objects are not reflected to the remote

acycliq opened this issue · comments

Hi

I am trying to trim the size of my repo with a series of commands that more or less look like this

git filter-repo --path-glob '*.tif' --invert-paths
git filter-repo --invert-paths --path /some/file.txt

git remote add origin https://github.com/username/myrepo.git
git push origin --force --all

While my local copy .git/objects seems to have been reduced (from 1.1GB down to 220MB) when I clone my github repo then:

  • It takes ages to download, which is an indication that my repo on GitHyb is still huge
  • When cloning is finished and I look into the .git/objects folder then I notice that this is still really big, which I imagine means that the changes have not been reflected to Girhub when I run git push origin --force --all

What am I doing wrong please? How can update my remote with the changes and reduce its size?

git push origin --force --all

From the manual:

all, --branches
Push all branches (i.e. refs under refs/heads/); cannot be used
with other .

If I had to guess, I'd say your repository also had tags. Since you didn't bother to push the tags, you now have a mixed history in this repository, where the tags point to the old history, and the branches to the new history. And you have to download both histories when you clone, which is probably a little bigger than what you started with.

Further, even if you do forcibly push the tags, then anyone else who has already cloned your repository can't get the corrected history without forcibly deleting the tags (or, preferably, just deleting their entire clone and recloning).

However, even that isn't foolproof, because it's possibly for the filter-repo commands to delete a branch, in the rare case that everything in it's history is deleted by the commands you specify. In such a case, there is nothing to push to the remote, so whatever branch was already there will simply persist. And that'll give you a mix of old and new history.

There's all kinds of gotchas with pushing the rewritten history back to the original remote. That's why I strongly advise people not to do that, unless they understand all the ramifications. Please read the entire DISCUSSION section of the manual before proceeding. Make sure to compare git ls-remote $URL with git show-ref and make sure that origin doesn't have any references differing from your local copy. (That can be difficult with e.g. pull or merge request references that repository forges don't allow you to update.) If the origin differs from what you have locally, you may need to manually push more, or manually delete references. It's often easier to just push to a new URL.

Anyway, hope that helps.