5

my git repository is quite big and I would like to bring its size down by removing some big files, which I added in the past and already removed later on, but which are still in the git history. Now I found the git filter-branch --tree-filter command. So i tried this:

git filter-branch --tree-filter 'DEL /content/de/files/bigfile.zip' --all 

(I'm on Windows).

But the result of invoking this command is:

fatal: ambiguous argument '/content/de/files/bigfile.zip'': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' 

I don't know, what to do. In the current working directory, the file is indeed not present. But it is still there in a couple of old commits in the history. My understanding was, that the command would remove the file from every commit.

8
  • You sure you want that leading /? Commented May 20, 2016 at 15:44
  • 3
    This is much faster as an index filter, you're not touching content so no need to load the worktree. git filter-branch --index-filter 'git update-index --force-remove content/de/files/bigfile.zip' -- --all Commented May 20, 2016 at 15:49
  • thanks, will try. To your first comment: I also tried without leading /, but it didn't make a difference. Commented May 20, 2016 at 16:05
  • hm, tried exactly as you have it above, then it says: fatal: bad revision 'update-index' Commented May 20, 2016 at 16:08
  • Ahhh, I have to use " instead of '. Commented May 20, 2016 at 16:10

2 Answers 2

10

So the actual mistake in my version was, that I used single quotes instead of double quotes. Seems like, at least on Windows, you have to use those.

That said, the comments from jthill and the answer from Roberto probably present better solutions to the task at hand.

Sign up to request clarification or add additional context in comments.

2 Comments

fatal: bad revision 'checkout' is the error i got and double quotes fixed it!
On Windows git filter-branch delegates to git/mingw64/libexec/git-core/git-filter-branch running under MinGW Bash, so running git from a Command Prompt will launch Bash, which in turn will launch the command passed to --filter-xxx under Bash. Since this is in MinGW the command can be a batch file. Escaping rules are weird, we can use MinGW Bash syntax inside double quotes (properly escaped for Command Prompt, so --msg-filter sees the parameter correctly. Note that ` is not usable inside the --filter-xxx` parameter because it'll be executed through eval "$xxx", need `\` instead.
1

You might want to consider the BFG, a faster and simpler alternative to git filter-branch. The equivalent command is :

$ bfg --delete-files bigfile.zip

https://rtyley.github.io/bfg-repo-cleaner/

Disclaimer : I am the author of the BFG

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.