How to permanently delete a commit from Git's history?

前端 未结 5 1971
甜味超标
甜味超标 2021-02-04 16:02

How can I permanently delete a commit from Git\'s history?

One of the developers on the team has accidentally committed a 200 MB file and pushed it to our Git server. It

5条回答
  •  醉梦人生
    2021-02-04 16:44

    I'd suggest you try The BFG - it won't remove those two commits, but it will rewrite history to get rid of the bulky files from your history.

    Carefully follow the BFG's usage instructions - the core part is just this:

    $ java -jar bfg.jar  --strip-blobs-bigger-than 100M  my-repo.git
    

    It's also substantially faster than git-filter-branch on big repositories - you might find this speed comparison video interesting - the BFG running on a Raspberry Pi, git-filter-branch running on a quad-core Mac OS X box... http://youtu.be/Ir4IHzPhJuI ...which will be faster!?

    Note that after the cleanup you should run git gc to get Git to recognise it doesn't need to store those big objects anymore and free-up disk space in that copy of the repository. git gc usually happens periodically on most hosted versions of Git, so when you push the cleaned history to your main Git server, that server will eventually free-up it's disk space too. Perhaps surprisingly, you don't have to wait for that git gc to run before users cloning fresh copies of your cleaned repo get just the cleaned history.

    Full disclosure: I'm the author of the BFG Repo-Cleaner.

提交回复
热议问题