I'm using VS code + git version 2.20.1 on macOS. Sometimes, when I switch throughout branches, files of other branches are wrongly retained in the current one.
Those files are not present in .gitignore
and they are not uncommitted changes.
For example if I have those committed files:
- branch_a: file1,file2
- branch_b: file2
if I checkout branch_a
in VS Code, I commit all changes and then I switch to branch_b
, I still have file1
in my working dir.
Oddly enough, file1
is somehow "invisible" to git. Indeed, this is not considered a potential change to branch_b
. This is just ignored even if it is actually on the file system. Let me clarify this from the command line point of view.
$ [git: branch_a] ls
file1 file2
$ [git: branch_a] git status
nothing to commit, working tree clean
$ git checkout branch_b
Switched to branch 'branch_b'
Your branch is up to date with 'origin/branch_b'.
$ [git: branch_b] ls
file1 file2
however, file1
shouldn't be here, but...
$ [git: branch_b] git status
nothing to commit, working tree clean
working tree is considered clean, and even if I rm
or I modify the file, git does not detect any changes:
$ [git: branch_b] rm file1
$ [git: branch_b] ls
file2
$ [git: branch_b] git status
nothing to commit, working tree clean
This issue is not systematic but it happens only sometimes. A similar problem has been reported in this SO question and it seems related to a kind of lock managed by VS Code (or by other Code Editors)
I'm wondering if there is a way to avoid this behavior and therefore if I can avoid to clean stale files with git reset --hard
+ git clean -f -d
.