How to remove file from Git history?

后端 未结 7 863
时光说笑
时光说笑 2020-11-28 03:04

Some time ago I added info(files) that must be private. Removing from the project is not problem, but I also need to remove it from git history.

I use Gi

7条回答
  •  攒了一身酷
    2020-11-28 03:35

    • First of all, add it to your .gitignore file and don't forget to commit the file :-)
    • You can use this site: http://gtiignore.io to generate the .gitignore for you and add the required path to your binary files/folder(s)

    • Once you added the file to .gitignore you can remove the "old" binary file with BFG.


    How to remove big files from the repository

    You can use git filter-branch or BFG. https://rtyley.github.io/bfg-repo-cleaner/

    BFG Repo-Cleaner

    an alternative to git-filter-branch.

    The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history:

    * Removing Crazy Big Files*
    * Removing Passwords, Credentials & other Private data

    Examples (from the official site)

    In all these examples bfg is an alias for java -jar bfg.jar.

    # Delete all files named 'id_rsa' or 'id_dsa' :
    bfg --delete-files id_{dsa,rsa}  my-repo.git
    

提交回复
热议问题