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

Bug in git-filter-branch example

From
IAIvo Anjo <knuckles@gmail.com>
Date
Feb 1, 2010, 11:48 UTC
Message-ID
<557ea2711002010348m57aa31fesd1047cbe3f01cb0b@mail.gmail.com>

I've been working on importing my svn repo into git, and while moving some things around using git-filter-branch I ran into a bug in the example provided on the manpage:

    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
The problem is with filenames that use complex utf8 (non-ascii?) chars:
> ls -lah Papers/*Lea*

-rw-r--r-- 1 knuckles users 109K 2010-01-31 18:57 Papers/A Java Fork ⁄ Join Framework -- Lea.pdf

as you can see, I'm using '⁄' as a replacement for '/' on that filename, since I obviously can't use '/' on a filename. The problem is, git ls-files -s lists that file wrapped in quotes and with the char value escaped

100644 c09309342037fa7d91f37651e2f16e981e4d739a 0    "Papers/A Java Fork \342\201\204 Join Framework -- Lea.pdf"

while other files aren't, so the simple sed line provided won't work, as it will output the new filename as newsubdir/"Papers...

I ended up using git filter-branch to remove the offending file ("if all you have is a hammer..."), and re-adding it after the move.

I'm also left wondering how many uses of git ls-files out there on the "internets" survive working on a filename such as this one. Maybe git ls-files should have an option to output the real utf8 file name instead of escaping the bytes...?

Ivo Anjo
Next: Jeff King
Message 1 of 3 in “Bug in git-filter-branch example”
  1. Ivo AnjoFeb 1, 2010
  2. Jeff KingFeb 1, 2010
  3. Johannes SixtFeb 1, 2010

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.