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

Re: Deleted folder keeps showing up?

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 4, 2009, 08:36 UTC
Message-ID
<7vfxb3yuma.fsf@alter.siamese.dyndns.org>
In-Reply-To
<8E56979B-5D85-4844-A492-8149EE9E9B2F@gmx.de>
Benjamin Buch <benni.buch@gmx.de> writes:
> Strangely, I can't reproduce the error  today.

If a branch has dir/file tracked, and another branch does not have anything tracked in dir/ directory at all, then switching from the former branch to the latter can remove dir/ only when you do not have any untracked files in there when you switch. Otherwise dir/ must stay behind to keep the untracked files.

You can see it by a simple experiment.
    $ rm -fr trial
    $ mkdir trial
    $ cd trial
    $ git init
    $ >elif
    $ git commit -m initial
    $ git branch lacksdir
    $ mkdir dir
    $ >dir/file
    $ git add dir/file
    $ git commit -m add-dir-file

Now, after this set-up, your 'master' has dir/file and 'lacksdir' does not have anything tracked in dir/ directory.

Observe:
    $ git checkout lacksdir
    $ find ??*
    elif
    $ git checkout master
    $ find ??*
    dir
    dir/file
    elif
    $ >dir/garbage
    $ git checkout lacksdir
    $ find ??*
    dir
    dir/garbage
    elif

If switching to 'lacksdir' removed the dir/ directory, whatever was in the untracked file dir/garbage will be lost. In the above exercise, I named it garbage, so a casual reader might get a false impression that it should be thrown away, but in real life workflow, it often happens that

 (1) you start doing some interesting experimental changes, while on
     'master';
 (2) you realize that this change does not belong to 'master', but belongs
     to some other branch, perhaps 'lacksdir';
 (3) you switch to the branch, to keep working.

Remember that, in git, your uncommitted changes to the index and the work tree do not belong to the branch. They try to follow you across branch switching. Since untracked new files are something potentially you might want to add after branch switching, we do not remove them. And because we choose not to remove dir/file, even though the commit at the tip of the lacksdir branch does not have anything tracked in dir/ directory, we cannot remove it from the work tree.

Previous: Benjamin BuchNext: Benjamin Buch
Message 4 of 6 in “Deleted folder keeps showing up?”
  1. Benjamin BuchSep 3, 2009
  2. Michael J GruberSep 4, 2009
  3. Benjamin BuchSep 4, 2009
  4. Junio C HamanoSep 4, 2009
  5. Benjamin BuchSep 7, 2009
  6. Jeff KingSep 4, 2009

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.