spec3
spec3

Reputation: 501

Why does Git show deleted files after switching a branch?

I keep seeing deleted files every time I switch branches. I already committed all the changes I had done.

git checkout master
D   eqs.jpg
D   old conversion.pdf
D   readme.txt

What should I do to avoid it?

Upvotes: 5

Views: 3527

Answers (2)

David Deutsch
David Deutsch

Reputation: 19035

This means that you have deleted the three files locally, but have not committed that deletion. If you want the files deleted from the repository as well, you need to git add --all and git commit. If you do not want them deleted, do a git checkout . to restore them locally.

Upvotes: 4

CodeWizard
CodeWizard

Reputation: 142164

You have to clean your working folder or to commit the changes.

How to clean the working dir?

# (x/X) are different case
git clean -Xfd
git clean -xfd 

-x

Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options.

This allows removing all untracked files, including build products.
This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.

-X

Remove only files ignored by Git.
This may be useful to rebuild everything from scratch, but keep manually created files.


How to clean cache?

# remove the file from cache git clean --cached


How to commit a removed file?

git add -A
# or:
git rm --cached <file>

Upvotes: -2

Related Questions