Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git checkout/pull doesn't remove directories?

Tags:

git

git-clean

I've got my repo @ github. I did some work at home and pushed it to github. It involved some deleting of files and directories. Now I'm on my work box, which had a copy of the code before deleting the files and directories.

I issued the following:

git remote update git checkout HEAD git pull origin HEAD 

It deleted all of the files it should have, but not the directories the files were in.

Two questions:

  1. Why did it not remove the directories?
  2. Is there a git command I can issue in the current state to remove them?
like image 627
mculp Avatar asked Sep 30 '09 16:09

mculp


2 Answers

Git doesn't track directories, so it won't remove ones that become empty as a result of a merge or other change. However, you can use git clean -fd to remove untracked directories (the -fd flag means force removal of untracked files and directories).

like image 178
mipadi Avatar answered Sep 22 '22 00:09

mipadi


I had same issue, in my case on build service (CI).. as GIT pulls all files without cleaning folders, all the bin / obj that were previously builded by the CI are dirty, so If I remove a test project, the bin will still contain the DLL and will mention tests that does not exist.

In order to solve this issue; this command seems to do the trick (at least for me)

git clean -fd -x 

where X will remove all untracked files:

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

like image 30
Yogurtu Avatar answered Sep 25 '22 00:09

Yogurtu