completely removing a file from git repo (from a certain point in time)
I've got a repo with about 2030 commits. At around commit 2000 a file was modified which caused it's size to travel from about 20M to 1.2 GB accidently. Is it possible to rewrite the history to remove this file but onl开发者_开发百科y from commit 2000? (I dont want to lose prior history of this file)
I was thinking git-filter-branch, but couldnt see a way to tell it the "from commit" - is it possible?
Cheers Mike
The man page for git-filter-branch contains the conclusive and authoritative example for this.
If you want to stop rewriting before a certain commit, say before tag01
:
git-filter-branch ...... -- master ^tag01
Substitute what you already have for the dots. tag01 may instead be any commit-ish (revspec)
PS: if you use tags don't forget --tag-name-filter cat
to rewrite these too
Why won't you
- Create a branch
new
at commit 2000, where you don't modify this file to a 1.2 GB file - Rebase
master
tonew
, with merge option-Xtheirs
- Garbage collect the repository to save disk space.
You might want to try the BFG Repo-Cleaner, a faster, simpler alternative to git-filter-branch
designed for removing large files or private data from Git repos.
Download the executable jar (requires Java 6 or above) and run this command:
$ java -jar bfg.jar --strip-blobs-bigger-than 100MB my-repo.git
Anything over 100MB in size (that isn't in your latest commit's file hierarchy) will be totally removed from your repository's history. All the versions of the file which are smaller than 100MB will be left alone, as specified in the question.
Full disclosure: I'm the author of the BFG Repo-Cleaner.
精彩评论