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

Filter-branch's "move tree to subdirectory" example fails with BSD sed?

From
Christopher Tiwald <christiwald@gmail.com>
Date
Apr 14, 2012, 16:00 UTC
Message-ID
<20120414160028.GD1012@gmail.com>

The "Move tree to subdirectory" example in the 'git filter-branch' manpage fails on Mac OSX 10.7.3, but succeeds on Ubuntu 10.04. I'm using git version 1.7.0.4, which happened to be the version installed on the Ubuntu VM I had laying around. I think it's a difference between 'sed' on the two systems.

The example:
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

Demonstrating the problem is with sed: git init "test" cd "test" mkdir -p subdirA/subdirB echo content > subdirA/subdirB/file git add . git commit -m "initial commit" git ls-files -s | sed "s-\t\"*-&newsubdir/-"

On Mac 10.7.3 the final command outputs: 100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0 subdirA/subdirB/file

On Ubuntu 10.04: 100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0 newsubdir/subdirA/subdirB/file

I can solve my immediate problem using Ubuntu, but is there a way we could rewrite the example to work on both systems? I'm afraid differences between BSD and GNU 'sed' are a bit beyond me.

-- Christopher Tiwald

Next: Johannes Sixt
Message 1 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.