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

[PATCH] git-filter-branch: add --egrep-filter option

From
Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
Date
Apr 15, 2011, 22:50 UTC
Message-ID
<4DA8CBB0.6080103@rivulet.ca>

The --subdirectory-filter will look for a single directory and then rewrite history to make its content the root. This is ok except for cases where we want to retain history of those files before they were moved into that directory.

The --egrep-filter option allows specifying an egrep regex for the files in the tree of each commit to keep. For example:

Directories we want are A, B, C, D and they exist in several different lifetimes. A and B exist sometimes together then B and C and finally then D.

e.g. git-filter-branch --egrep-filter "(A|B|C|D)"
Each commit will then contain different combination's of A or B or C or D (up to A and B and C and D).
---
  git-filter-branch.sh |   12 ++++++++++++
  1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 962a93b..2392ad6 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -101,6 +101,7 @@ USAGE="[--env-filter<command>] [--tree-filter<command>]
              [--index-filter<command>] [--parent-filter<command>]
              [--msg-filter<command>] [--commit-filter<command>]
              [--tag-name-filter<command>] [--subdirectory-filter<directory>]
+			[--egrep-filter<filter>]
              [--original<namespace>] [-d<directory>] [-f | --force]
              [<rev-list options>...]"

@@ -122,6 +123,7 @@ filter_msg=cat
  filter_commit=
  filter_tag_name=
  filter_subdir=
+filter_egrep=
  orig_namespace=refs/original/
  force=
  prune_empty=
@@ -191,6 +193,10 @@ do
  		filter_subdir="$OPTARG"
  		remap_to_ancestor=t
  		;;
+	--egrep-filter)
+		filter_egrep="$OPTARG"
+		remap_to_ancestor=t
+		;;
  	--original)
  		orig_namespace=$(expr "$OPTARG/" : '\(.*[^/]\)/*$')/
  		;;
@@ -317,6 +323,12 @@ while read commit parents; do
  		}
  	esac || die "Could not initialize the index"

+	if [ "$filter_egrep" ]; then
+
+		git ls-tree $commit | egrep "$filter_egrep" | git mktree | xargs git read-tree -i -m
+
+	fi
+
  	GIT_COMMIT=$commit
  	export GIT_COMMIT
  	git cat-file commit "$commit">../commit ||
-- 1.7.2.3
Next: Johannes Sixt
Message 1 of 5 in “git-filter-branch: add --egrep-filter option”
  1. git-filter-branch: add --egrep-filter optionMichael O'Cleirigh, Apr 15, 2011
  2. Johannes SixtApr 16, 2011
  3. Michael O'CleirighApr 17, 2011
  4. Jonathan NiederApr 19, 2011
  5. Phil HordApr 19, 2011

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.