Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

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.

like image 542
Sunil Kumar Avatar asked May 20 '15 09:05

Sunil Kumar


1 Answers

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

  • "How do I delete all empty directories in a directory from the command line?" (unix shell):
find . -empty -type d -delete
  • "How to delete empty folders using windows command prompt?" (Powershell):
Get-ChildItem -Recurse . | where { $_.PSISContainer -and @( $_ | Get-ChildItem ).Count -eq 0 } | Remove-Item
like image 149
VonC Avatar answered Nov 10 '22 13:11

VonC