How to remove old versions of media files from a git repository

后端 未结 5 453
不思量自难忘°
不思量自难忘° 2020-12-15 05:00

I have a Git repository with several huge media files (images and audio files). Several versions of these media files have been successively commited to the repo. The files

5条回答
  •  误落风尘
    2020-12-15 05:28

    Old thread but in case someone else stumbles along here…

    GitHub & Bitbucket both recommend using BFG Repo-Cleaner.

    See:
    GitHub: Remove Sensitive Data
    Bitbucket: Reduce Repository Size & Bitbucket: Maintaining a Git Repository

    Example to remove files over 1 Megabyte, as well as jpgs, pngs and mp3s that are not in HEAD:

    # First get the latest bfg.jar, then:
    $ git clone --mirror git://example.com/some-big-repo.git
    $ java -jar bfg.jar --strip-blobs-bigger-than 1M --delete-files '*.{jpg,png,mp3}' some-big-repo.git
    $ cd some-big-repo.git
    $ git reflog expire --expire=now --all && git gc --prune=now --aggressive
    $ git push
    

    Note: now you've pushed the updated revs, the remote repository should also run it's git gc …else you won't see the size reduction. (see e.g. https://stackoverflow.com/a/28782154/3419541)

    Finally, re-clone the repository to be sure that you don't accidentally re-commit the old media file blobs.

提交回复
热议问题