Git - how to delete an empty folder and push this change?

How can I delete an empty folder locally, and also this will happen for other collaborators who share the console using pull-push? I know that folders are not tracked in this sense by git, but the question remains.

eg. I moved the file to another folder and made a change (move).

But I can’t git rm name folder, because I get the "does not match" git rmdir name does not exist.

I can do git clean -f folder , but how to push it?

I can use rm directly to use this file, but how can I make this directory deletion correct and pushed to the repository, and then to the other when they pull out to delete the existing folder?

+52
git directory folder rm rmdir
Apr 09 2018-12-12T00:
source share
5 answers

Short answer: You cannot make changes to directories (added, deleted, etc.) because Git does not track directories on its own .

According to the FAQ :

Currently, the Git index (staging area) design only allows you to list files, and no one competent enough to make changes that allow empty directories has taken enough care of this situation to fix this.

Directories are added automatically when files are added to them. That is, directories should never be added to the repository and are not tracked by themselves.

So as for Git, your empty directory no longer exists.

I found that the habit of using git clean -fd eliminates the need to click on delete directories. However, git clean can remove items that you cannot delete (including any new files that you haven't done yet), so I prefer to use git clean -fdn first to see what will be deleted if I use the command.

It looks like you might be forced to talk with other developers to clear this directory.

+89
Apr 09 2018-12-12T00:
source share
 git add --all git clean -f -d git commit -m "trying to remove folders" git push 
+4
Feb 28 '16 at 0:14
source share

to delete empty folders

I wanted to delete the empty directory (folder) that I created, git cannot delete it, after some research, I found out that Git does not track empty directories. If you have an empty directory in your working project, you should simply delete it with

 rm -r folderName 

There is no need to involve Git. note this answer is only checked on local repositories,

0
Dec 19 '18 at 2:03
source share

You cannot empty empty folders. But if you want to clear empty folders in your cloned / local repo, commit your latest changes. Then simply delete all files except the .git folder in the local copy. Then reset everything changes again, which returns all the files, but leaves empty directories that it does not track.

-one
Jul 26 '16 at 10:53 on
source share

A slightly hacked way to create a fake file in a directory, commit it, and then delete it. Deleting this file will also delete the directory. So create the name /fake.txt

 git add name/fake.txt git commit -m "message" git rm name/fake.txt git commit -m "message2" 
-7
Jul 29 '14 at 15:04
source share



All Articles