Git: How to remove only empty directories (not tracked files) in the Git repository

By executing some pull, push, rebase, merge ... some empty directories remained in my project.

Later I found out that Git does not track directories , and there is a command to delete such directories.

Git clean -fd
This command will clear all files that are not in your git repository, including folders.

but the above team also deletes all irreproducible files and directories, this is a big loss in current development projects.

Is there a way to delete only empty folders without touching untracked files.

+4
source share
1 answer

, ( ) git:

  • " Windows?":

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

(Powershell)

  • " ?":

    find . -empty -type d -delete
    
+2

Source: https://habr.com/ru/post/1588957/


All Articles