1

I'm working on a little repo. I have branches master, m1, m2, m3, m4 and m5. I recently worked on m4, created a directory and committed my changes. Now I checkout m5, but that directory I just created on m4 is still there. Trying to understand why that might be and if/what I should do about it.

e.g.

PS C:\Repos\mystuff> git co m5
Switched to branch 'm5'
PS C:\Repos\mystuff> git ls-tree -r --name-only m5
.gitattributes
.gitignore
LICENSE
README.md
PS C:\Repos\mystuff> git st
On branch m5
nothing to commit, working tree clean
PS C:\Repos\mystuff> ls


    Directory: C:\Repos\mystuff>


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2019-09-14  11:02 AM                04   <== old folder from m4
-a----       2019-07-23   7:25 PM             66 .gitattributes
-a----       2019-09-03   7:58 PM           5980 .gitignore
-a----       2019-07-23   7:25 PM           1065 LICENSE
-a----       2019-07-23   7:25 PM             32 README.md

Why is that old folder still showing in ls, even though it is not in the files for the branch and doesn't show as untracked?

Can/should I (safely) deleted it without messing up m4?

user1443098
  • 6,487
  • 5
  • 38
  • 67
  • 1
    Are there any files in `04`? Git does not track folders, only files. Checking out `m5` should remove the files in `m4` that are not in `m5`, but it won't delete the folder unless it's empty afterwards, e.g., if it contains any untracked files, Git would not remove those. – joanis Sep 14 '19 at 15:41
  • Is it possible that your `.gitignore` has something to do with this ? – Hugo y Sep 14 '19 at 16:11
  • @joanis Aha, the folder is empty. so that explains it! Thanks. If you submit it as an answer I'll accept it. – user1443098 Sep 14 '19 at 18:55

1 Answers1

3

Git does not track folders, only files.

Checking out m5 should remove the files in m4 that are not in m5, but it won't delete the folder unless it's empty afterwards.

For example, if it contains any untracked files, Git would not remove those files or the folder.

joanis
  • 10,635
  • 14
  • 30
  • 40