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

Bug in filter-branch -d option, new files are dumped into parent

From
Martin Erik Werner <martinerikwerner@gmail.com>
Date
Apr 2, 2013, 12:32 UTC
Message-ID
<1364905941.19800.24.camel@mas>

Hi, I think I have stumbled on a bug in the -d option of git filter-branch.

It seems like in the final stage of filter-branch, regardless of where -d is set, it will make updates to the "working directory" as being the parent of the -d directory, and the actual working directory is left as it were before the filtering.

For example if using -d /tmp/git-rewrite, the new checkout files are dumped into /tmp.

A simple test scenario:

### mkdir test cd test git init

echo foo >foo git add foo git commit -m"foo" echo bar >bar git add bar git commit -m"bar"

git checkout -b rewrite git filter-branch -d /tmp/git-rewrite --tree-filter 'echo baz >baz' -- rewrite # git status # shows 'baz' as unstaged-deleted in the working directory # # ls /tmp/ # shows the 'baz' file created in the root, above git-rewrite # # git log --stat --oneline # does show expected result though # # if you run it again you'll get an error because of the /tmp/baz file git reset --hard master git filter-branch -f -d /tmp/git-rewrite --tree-filter 'echo baz >baz' -- rewrite # Rewrite afac18542ac3d432b647866f5ac6918b81b3bb78 (2/2) # Ref 'refs/heads/rewrite' was rewritten # error: Untracked working tree file 'baz' would be overwritten by merge. # # At this point, 'baz' is instead staged-deleted in the working directory ###

-- 
Martin Erik Werner <martinerikwerner@gmail.com>
Next: Jeff King
Message 1 of 2 in “Bug in filter-branch -d option, new files are dumped into parent”
  1. Martin Erik WernerApr 2, 2013
  2. filter-branch: return to original dir after filteringJeff King, Apr 2, 2013

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.