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

[PATCH 1/1] Documentation/git-filter-branch: add --index-filter example

From
Michael O'Cleirigh <michael.ocleirigh@rivulet.ca>
Date
Apr 27, 2011, 18:08 UTC
Message-ID
<1303927684-6513-2-git-send-email-michael.ocleirigh@rivulet.ca>
In-Reply-To
<1303927684-6513-1-git-send-email-michael.ocleirigh@rivulet.ca>

Added an example using git ls-tree on the $GIT_COMMIT and then filtering what should remain in the history using egrep.

This allows multiple paths accross history to be retained when filtering a branch.
---
 Documentation/git-filter-branch.txt |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 9dc1f2a..e80bc01 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -248,6 +248,19 @@ 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:
 
+-----------------------------------------------------------------------------------------------------------------------------------
+git filter-branch --prune-empty --index-filter 'git ls-tree $GIT_COMMIT | egrep \
+"(top-dir-A|top-dir-B|consolidated-dir-C)" | git mktree | xargs git read-tree -i -m'
+-----------------------------------------------------------------------------------------------------------------------------------
+
+The --subdirectory-filter works great when all commits of interest have
+that path but sometimes you have a history that contains an irregular 
+structure. i.e. that was reorganized at some point and you would like to 
+keep the prior history.
+
+For each commit the top-dir-A, top-dir-B and consolidated-dir-C paths (if they exist)
+are kept (and everything else discarded). 
+
 -------------------------------------------------------------------
 git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' HEAD
 -------------------------------------------------------------------
-- 
1.7.2.3
Previous: Michael O'CleirighNext: Johannes Sixt
Message 2 of 4 in “Add new --index-filter example to git-filter-branch.txt”
  1. 0/1 Add new --index-filter example to git-filter-branch.txtMichael O'Cleirigh, Apr 27, 2011
  2. 1/1 Documentation/git-filter-branch: add --index-filter exampleMichael O'Cleirigh, Apr 27, 2011
  3. Johannes SixtApr 27, 2011
  4. Sverre RabbelierApr 27, 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.