6

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.

1
  • Stash or commit the files you want to keep. There's no reason to have uncommitted changes sitting around in the file system for a long time. Commented Jan 17, 2020 at 22:14

1 Answer 1

5

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 
Sign up to request clarification or add additional context in comments.

2 Comments

,Thanks for your update.But I have a scenario in my product, Users create projects and each project is auto configured to VCS(git repo).And users can create some resource(like a folder with four files) then they can revert that specific resource any time with out committing to repo.In this case files are deleted but not directory.I am using git apis to interact repo.
@SunilKumar just call one of these commands after any delete or checkout action (don't call it when they create a folder as it will disappear right after creation). these commands just work, they will delete all empty folders and git don't track them.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.