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.
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.
I believe the other answers are mostly correct, but not quite. Figured I would add my own answer in case it helps any other Git newbies.
First off, I checked for ignore rules and for hidden files, but none of either turned up.
What is getting left behind in Tests
when I switch over to F2
is empty directories. They're not ignored or hidden or anything, they were just never checked in due to being empty. It seems the checkout
command will remove all the versioned files, but leave the empty directories alone. The clean
command will clean these up.
Looks like Git is working as expected. Thanks!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With