Reputation: 2102
One of my collages reorganized one of our projects in Git, which resulted in several of the directories that were there previously being deleted. When I pulled from development this morning using Source Tree the files in the directories that were deleted are gone, but the directories persisted on my local copy. Is there a way that when something like this happens that the directory can be deleted on pull?
This may be a duplicate question, but everything that I can find is addressing recovering deleted files.
Upvotes: 1
Views: 1230
Reputation: 1283
Git tracks files, not directories. So to git, an empty directory just does not exist.
However you can use the git clean -df
command to delete all untracked files and directories. Be careful though as this will delete any untracked files as well.
From the man pages:
Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.
Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for example, be useful to remove all build products.
If any optional <path>... arguments are given, only those paths are affected.
-d
Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository, it is not removed by default. Use -f option twice if you really want to remove such a directory.
-f, --force
If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.
-i, --interactive
Show what would be done and clean files interactively. See "Interactive mode" for details.
-n, --dry-run
Don't actually remove anything, just show what would be done.
Upvotes: 2