Git checkout/pull doesn't remove directories?

前端 未结 5 2097
暗喜
暗喜 2020-11-30 17:57

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

5条回答
  •  一向
    一向 (楼主)
    2020-11-30 18:22

    Git doesn't track directories, files (with their path). Git creates all the directories for those paths if they don't exist yet (cool!), however it does not delete them if all the files contained in a path are moved or deleted (not cool ☹ ... but there's reasons).

    Solution (once you have pulled / fast-forwarded / merged):

    git stash --include-untracked
    git clean -fd
    git stash pop
    

    If you don't stash before clean, you will loose all your untracked files (irreversibly).

    Note: since this cleans all ignored files too, you might need to run some of your build scripts again to recreate project metadata (ex: ./gradlew eclipse). This also delete directories that are empty and that were never part of paths of git files.

提交回复
热议问题