2

This repository had a large subdirectory of large files that months ago I removed from the commit and that I now want to remove from the repo forever. The massive subdirectory is no longer in the download but the objects directory is enormous.

The checkouts/clones take a long time and I believe this is because of the large .git/objects directory.

repo
    <files to keep>
        <massive subdirectory>

I want to remove the massive subdirectory.

https://stackoverflow.com/questions/10067848/remove-folder-and-its-contents-from-git-githubs-history

The link above has a long discussion of a procedure that I've put to this script :

    #!/bin/bash

    if [ -z "$1" ]; then
      echo "missing argument: subdirectory to remove"
      exit
    fi

    git filter-branch --tree-filter 'rm -rf $1' --prune-empty HEAD
    git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
    echo $1/ >> .gitignore
    git add .gitignore
    git commit -m 'Removing $1 from git history'
    git gc
    git push origin master --force

I have run this without obvious errors and then cloned the repo to find that the .git/objects directory is not reduced in size.

Is the script missing something? Am I missing something? Has a recent version of git introduced a more direct feature for this requirement?

Is there another approach?

1
  • 1
    filter-branch is your answer; I don't have the details in front of me. Commented May 7, 2019 at 23:19

1 Answer 1

0

This answer using index-filter worked for me where the others did not :

https://stackoverflow.com/a/32886427/4386557

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .