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

Directory in one branch, file in another = can't switch branches

From
Steven Grimm <koreth@midwinter.com>
Date
Mar 16, 2007, 22:17 UTC
Message-ID
<45FB1762.7040505@midwinter.com>

We've hit this problem with a git-svn-based repository where some stuff got reorganized, but it happens in plain git too; if you have a branch with a file called, say, "foo" and another branch with a file called "foo/bar", you can't switch between branches even if there are no uncommitted edits in either branch.

To reproduce (I'm using version 1.5.0.1.74.g2470):
% git init-db
Initialized empty Git repository in .git/
% echo "this is a test file" > testing
% git add testing
% git commit -a -m "initial commit on master"
Created initial commit 1a9cb1bf3a5475f0bb05d1e7c59839ba0a388be7
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 testing
% git checkout -b with-dir
Switched to a new branch "with-dir"
% mv testing testing-
% mkdir testing
% mv testing- testing/datafile
% git add testing/datafile
% git commit -a -m "commit with subdir"      
Created commit cdcb2af2a8dae8a2c5c3c143cb00b4863291cc17
 2 files changed, 1 insertions(+), 1 deletions(-)
 delete mode 100644 testing
 create mode 100644 testing/datafile
% git checkout master
fatal: Untracked working tree file 'testing' would be overwritten by merge.

You can work around it by renaming the directory, but git should really blow away the directory if it doesn't contain any untracked / modified files.

-Steve
Next: Steven Grimm
Message 1 of 2 in “Directory in one branch, file in another = can't switch branches”
  1. Steven GrimmMar 16, 2007
  2. Steven GrimmMar 16, 2007

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.