tags:

views:

2829

answers:

4

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 have tried

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch imgs" HEAD

and

git filter-branch --tree-filter 'rm -fr imgs' HEAD

but the size of the git repo remains unchanged. Any ideas?

Thanks

+6  A: 

The ProGit book has an interesting section on Removing Object.

it does end with a:

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 ;)

VonC
+4  A: 

git-filter-branch by default saves old refs in refs/original/* namespace.
You need to delete them, and then do "git gc --prune=now".

Jakub Narębski
+5  A: 

Actually none of these techniques workedfor me. I found the most reliable was was to simply pull locally into another repo:

git pull file://$(pwd)/myGitRepo

It also saves you the hassle of deletig old tags.

see the story on my blog: http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/

Antony Stubbs
This seems to be the deal close for me. I have documented the Windows specific steps here: http://www.somethingorothersoft.com/?p=80
Igor Zevaka
+1  A: 

If you want to go the manual cleanup route, there are some more files that may also contain a ref to the position of your original branch before the git-filter-branch. For example, I filtered my "home" branch:

.git/info/refs:

179ad3e725816234a7182476825862e28752746d refs/original/refs/heads/home

.git/packed-refs:

179ad3e725816234a7182476825862e28752746d refs/original/refs/heads/home

After I removed those lines, gitk did not show the old commits any more.

Rainer Blome
worked for me, although I kindof wonder if this just fixed the gitk view or if the refs will actually be gc'd now
Brandon Thomson