Sunil Kumar
Sunil Kumar

Reputation: 5647

Git : How to remove only empty directories(not un-tracked files) in a git repo

By doing some pull's,push's,rebase's,merge's...some empty directories left in my project.

Later I came to know, Git doesn't track directories and there is a command to delete such directories.

git clean -fd
This command will clean up all of the files that are not part of your git repository - including the folders.

but above command is also deleting all untracked files and directories,this is a big lose to ongoing development projects.

Is there any way to delete only empty folders with out touching un-tracked files.

Upvotes: 6

Views: 2389

Answers (1)

VonC
VonC

Reputation: 1323175

It seems easier to delegate that specific task (deleting empty folders) to the shell instead of git:

find . -empty -type d -delete
Get-ChildItem -Recurse . | where { $_.PSISContainer -and @( $_ | Get-ChildItem ).Count -eq 0 } | Remove-Item

Upvotes: 5

Related Questions