Re: Deleted folder keeps showing up?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Benjamin Buch <benni.buch@xxxxxx> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]