Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?

Tags:

git

I learn "tree" and "index" from the this aritcle: Learning Git Internals by Example

but when it come to "git filter-branch" command, I don't know what is the difference between "--tree-filter" and "--index-filter".

like image 684
GoTop Avatar asked Mar 28 '16 02:03

GoTop


People also ask

What is the purpose of git filter branch `?

git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .

What is git filtering content?

In git you can define "filters" that affect the process of moving files from the index to the work tree ("smudge" filters) and from the work tree to the index ("clean" filters). Typically you'll find a . gitattribute file that associates the filters with files at specific paths.

How do I remove sensitive data from git history?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history. To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool.


1 Answers

The short version is that --tree-filter checks out each commit into a temporary directory, runs your filter command, and builds a new commit from whatever is now in the temporary directory; while --index-filter copies each commit into the index, runs your filter command, and builds a new commit from whatever is now in the index.

Copying a commit to the index is much1 faster than checking out the commit. Building a commit from the index is faster than building a commit from a directory. As a result, using the index filter is much faster than using the tree filter. It's not as easy to script for, though.


1The exact speed difference depends on your temporary directory: an in-memory file system is faster than an on-SSD file system which is faster than on-spinning-media, so you gain more if you're using spinning media than if you can point the tree filter to an in-memory file system. But even then the index filter is still faster.

On actual disks, I've seen about a factor of 100 or so (hence an index filter that takes 2 minutes translates to a tree filter that takes 3+ hours).

like image 173
torek Avatar answered Oct 07 '22 09:10

torek