Switching branches in Git doesn't remove directories

Mike Christensen

I've created two branches in Git:

git branch F1
git branch F2

Next, I switch over to F1:

git checkout F1

I rename my UnitTests directory to Tests:

git mv .\UnitTests .\Tests
git commit . -m "Moving unit tests to Tests directory"

At this point, I have a master branch with a UnitTests directory, an F2 branch with a UnitTests directory and a F1 branch with a Tests directory. So, I switch over to F2:

git checkout F2

When I do this, I now see the UnitTests directory added back, but I also see the Tests directory (From the F1 branch) still there. It even has all the same files.

I can force it to be removed by running:

git clean -fd

However, I'm wondering why remnants from the old branch are lingering around. I've looked at a few other potential duplicates, but all of them note cases where my move was not yet committed. I clearly committed the move to F1 before switching branches.

Any ideas? I'm running git version 1.9.2.msysgit.0 on Windows.

Udy

It is because you have files or directories (could be empty) that git ignore (hidden or explicit ignored) in the UnitTests directory

Therefore, git wouldn't delete these files so he keeps them in the directory.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Remove old remote branches from Git

From Dev

Git diff different directories across branches

From Dev

Git in TFS - Remove branches after merging

From Dev

git clean -ndX doesn't remove directory

From Dev

git fetch origin doesn't fetch all branches

From Dev

Git doesn't clone all directories

From Dev

Git: remove -f and --force branches

From Dev

MATLAB does not recognize".m" file changes after switching branches in git

From Dev

Switching Git branches inside an Android Repo project

From Dev

Switching branches in Git with external dependencies

From Dev

Git for Windows doesn't work correctly with network directories

From Dev

git doesn't see branches after reinstallation osx

From Dev

Xcode 7 doesn't show new remote branches using Git

From Dev

How do I deal with vim buffers when switching git branches?

From Dev

git desktop client doesn't show all remote branches

From Dev

git fetch origin --prune doesn't delete local branches?

From Dev

state of git is confused by switching branches in a script

From Dev

Visual Studio 2013 remove deleted git branches

From Dev

Git doesn't show untracked directories

From Dev

Git correct switching between branches

From Dev

git clean -ndX doesn't remove directory

From Dev

Switching Git branches and disregarding changes

From Dev

Xcode warning when switching branches in git

From Dev

Git doesn't clone all directories

From Dev

git clone doesn't import all remote branches

From Dev

Why Git allows switch branches and (!!!) doesn't update the working tree after this switching?

From Dev

Git doesn't save created branches

From Dev

state of git is confused by switching branches in a script

From Dev

Git internals: why `.git/refs/remotes/origin/` doesn't have all branches

Related Related

  1. 1

    Remove old remote branches from Git

  2. 2

    Git diff different directories across branches

  3. 3

    Git in TFS - Remove branches after merging

  4. 4

    git clean -ndX doesn't remove directory

  5. 5

    git fetch origin doesn't fetch all branches

  6. 6

    Git doesn't clone all directories

  7. 7

    Git: remove -f and --force branches

  8. 8

    MATLAB does not recognize".m" file changes after switching branches in git

  9. 9

    Switching Git branches inside an Android Repo project

  10. 10

    Switching branches in Git with external dependencies

  11. 11

    Git for Windows doesn't work correctly with network directories

  12. 12

    git doesn't see branches after reinstallation osx

  13. 13

    Xcode 7 doesn't show new remote branches using Git

  14. 14

    How do I deal with vim buffers when switching git branches?

  15. 15

    git desktop client doesn't show all remote branches

  16. 16

    git fetch origin --prune doesn't delete local branches?

  17. 17

    state of git is confused by switching branches in a script

  18. 18

    Visual Studio 2013 remove deleted git branches

  19. 19

    Git doesn't show untracked directories

  20. 20

    Git correct switching between branches

  21. 21

    git clean -ndX doesn't remove directory

  22. 22

    Switching Git branches and disregarding changes

  23. 23

    Xcode warning when switching branches in git

  24. 24

    Git doesn't clone all directories

  25. 25

    git clone doesn't import all remote branches

  26. 26

    Why Git allows switch branches and (!!!) doesn't update the working tree after this switching?

  27. 27

    Git doesn't save created branches

  28. 28

    state of git is confused by switching branches in a script

  29. 29

    Git internals: why `.git/refs/remotes/origin/` doesn't have all branches

HotTag

Archive