Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git not removing files when switching branch

Tags:

git

macos

Sometimes when switching branches using Git (version 1.7.2.1) it does not seem to remove the files/directories I created specific to the branch I switched away from. Neither does it list it as untracked when running git status or any log entries for those files.

This only happens occasionally and I'm not sure why or how to reset it so the files not belonging to the current branch gets deleted. If I delete the files manually, it gets in sync again (as in gets deleted/revived when switching branch).

Anyone experienced this?

like image 554
baloo Avatar asked Oct 07 '10 20:10

baloo


People also ask

Does switching branches change files?

When you switch branches, files that are not tracked by Git will remain untouched. Since Git does not know about new_file. dat , it will not just delete it. The file new_file.

What happens to untracked files when switching branches?

Take away: changing branches does not touch/change/remove untracked or checked in files. Remember that the working directory and index are not 'cleared' before the branch content is loaded into it!


1 Answers

I have seen this too. I usually just do a git reset --hard followed by a git clean -f -d and it usually does the trick.

It seems to definitely happen the most often when my IDE has a lock on one of the files in the branch i'm switching from.

like image 194
Chris Kooken Avatar answered Oct 01 '22 10:10

Chris Kooken