git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Documentation: Another example for git-filter-branch

From
ABAlex Bennee <kernel-hacker@bennee.com>
Date
Mar 28, 2008, 18:07 UTC
Message-ID
<1206727676.9819.22.camel@malory>
In-Reply-To
<47ED204E.3020602@viscovery.net>
On Fri, 2008-03-28 at 17:43 +0100, Johannes Sixt wrote:
Show 7 quoted lines
> Alex Bennee schrieb:
> > git-checkout dev-branch
> > git-filter-branch --tree-filter  'rm -rf big_dira big_dirb' HEAD
> 
> You really shouldn't do it this way, unless you do it on a ramdisk. Better
> use an --index-filter. This is modeled after the last example in the man
> page (and, of course, untested):
I missed the implications of the last example...
Show 9 quoted lines
> git filter-branch --index-filter \
>         'git ls-files -s |
> 	 grep -v "	big_dira" |
> 	 grep -v "	big_dirb" |
>                 GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>                         git update-index --index-info &&
>          mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
> 
> where the space before big_dir is actually a literal TAB!

Good example. Maybe we should add the following (because plenty of examples is always a good thing IMHO)?

>From 341b480bad4ed9f99a54dc66ba20b0cead4594b5 Mon Sep 17 00:00:00 2001
From: Alex Bennee <Alex.Bennee@cambridgebroadband.com>
Date: Fri, 28 Mar 2008 18:00:20 +0000
Subject: [PATCH] Update git filter-branch examples for cleaning directories
I had to do this to a tree I imported from CVS which had a lot of cruft in it
which was taking ages. Luckily Johannes Sixt submitted this scriplet on the list
before I finished which makes things clearer.
---
 Documentation/git-filter-branch.txt |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 543a1cf..0e4b581 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -184,6 +184,27 @@ git filter-branch --index-filter 'git update-index --remove filename' HEAD
 
 Now, you will get the rewritten history saved in HEAD.
 
+If you need to remove whole directories it is tempting to use "rm -rf"
+in the --tree-filter form, however this will generate a lot of disk IO
+on big trees. Hence it's more preferable to use the index filter. For
+example:
+
+--------------------------------------------------------------------------
+git filter-branch --index-filter \
+       'git ls-files -s |
+        grep -v "      big_dira" |
+	grep -v "      big_dirb" |
+		GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
+                git update-index --index-info &&
+	mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
+--------------------------------------------------------------------------
+
+NB: The grep is matching literal TABs from the output of "git
+ls-files". Try <ctrl-v><tab> if your shell keeps giving you a directory
+listing every time you hit tab.
+
+
+
 To set a commit (which typically is at the tip of another
 history) to be the parent of the current initial commit, in
 order to paste the other history behind the current history:
-- 
1.5.5.rc0.6.gdeda.dirty





--
Alex, homepage: http://www.bennee.com/~alex/
We reject: kings, presidents, and voting. We believe in: rough consensus
and working code. -- Dave Clark
Previous: Johannes SixtNext: Mike Hommey
Message 7 of 14 in “Truncating and cleaning a imported git repositary to make it more usable”
  1. Alex BenneeMar 28, 2008
  2. Avery PennarunMar 28, 2008
  3. Alex BenneeMar 28, 2008
  4. Alex BenneeMar 28, 2008
  5. Alex BenneeMar 28, 2008
  6. Johannes SixtMar 28, 2008
  7. Documentation: Another example for git-filter-branchAlex Bennee, Mar 28, 2008
  8. Mike HommeyMar 28, 2008
  9. Alex BenneeMar 29, 2008
  10. Jakub NarebskiMar 29, 2008
  11. Johannes SixtMar 31, 2008
  12. Jeff KingMar 28, 2008
  13. Jeff KingMar 28, 2008
  14. Michael HaggertyMar 29, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.