Remove a directory permanently from git

后端 未结 6 1029
广开言路
广开言路 2020-11-30 20:44

In my personal git repo, I have a directory that contains thousands of small images that are no longer needed. Is there a way to delete them from the entire git history? I h

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 21:19

    The ProGit book has an interesting section on Removing Object.

    It does end with this:

    Your history no longer contains a reference to that file.
    However, your reflog and a new set of refs that Git added when you did the filter-branch under .git/refs/original still do, so you have to remove them and then repack the database. You need to get rid of anything that has a pointer to those old commits before you repack:

    $ rm -Rf .git/refs/original
    $ rm -Rf .git/logs/
    $ git gc
    $ git prune --expire 
    

    (git prune --expire is not mandatory but can remove the directory content from the loose objects)
    Backup everything before doing those commands, just in case ;)

提交回复
热议问题