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

[RFC/PATCH 2/2] docs/filter-branch: clean up newsubdir example

From
Jeff King <peff@peff.net>
Date
Apr 16, 2012, 16:03 UTC
Message-ID
<20120416160300.GB1350@sigill.intra.peff.net>
In-Reply-To
<20120416152737.GB14724@sigill.intra.peff.net>

Over the years, this simple example has ended up quite hard to read because of the number of special cases that must be handled. Let's simplify it a bit:

  1. Use the new "index-info --clear" to avoid the need for
     a temporary index.
  2. Use "-z" and "perl -0" to avoid dealing with quoting
     issues. As a bonus, using perl means that "\t" will
     work consistently in regexps (the previous example
     using sed was reported to fail on OS X).
  3. Change the indentation to keep one logical unit per
     line and avoid extra backslash-escaping.
Signed-off-by: Jeff King <peff@peff.net>
---
 Documentation/git-filter-branch.txt |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt
index 0f2f117..3df138f 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -358,11 +358,11 @@ git filter-branch ... D..H --not C
 To move the whole tree into a subdirectory, or remove it from there:
 
 ---------------------------------------------------------------
-git filter-branch --index-filter \
-	'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
-		GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
-			git update-index --index-info &&
-	 mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
+git filter-branch --index-filter '
+	git ls-files -sz |
+	perl -0pe "s{\t}{\tnewsubdir/}" |
+	git update-index -z --clear --index-info
+' HEAD
 ---------------------------------------------------------------
 
 
-- 
1.7.9.6.8.g992e5
Previous: Christopher TiwaldNext: Junio C Hamano
Message 7 of 9 in “Filter-branch's "move tree to subdirectory" example fails with BSD sed?”
  1. Christopher TiwaldApr 14, 2012
  2. Johannes SixtApr 14, 2012
  3. Jeff KingApr 16, 2012
  4. 1/2 update-index: add --clear optionJeff King, Apr 16, 2012
  5. Christopher TiwaldApr 16, 2012
  6. Christopher TiwaldApr 17, 2012
  7. 2/2 docs/filter-branch: clean up newsubdir exampleJeff King, Apr 16, 2012
  8. Junio C HamanoApr 16, 2012
  9. Jeff KingApr 16, 2012

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.