4

I init folder. Added all files commit them and than push them. Everything was looking fine...but i am missing some files and folder.

To example my .gitignore file

web/images/uploaded_profile_pictures/* 

But there should be uploaded_profile_pictures folder... how to write it in .gitignore to ignore ONLY the content of the folder.. and keep the folder?

And second problem... why is there missing content???

After push

enter image description here

2
  • you can't commit an empty folder, because internally git does not think in folders and files, but in one big binary blob Commented May 21, 2013 at 17:29
  • @JWhy answer should be accepted. Commented Dec 27, 2021 at 1:44

2 Answers 2

10

There can't be folders without files in Git repositories, Git will always ignore empty folders (or folders that contain only ignored files). A common workaround is to create placeholder files in empty directories that you want to include in your Git repository.

touch web/images/uploaded_profile_pictures/.empty git add web/images/uploaded_profile_pictures/.empty 

Now for the .gitignore:

web/images/uploaded_profile_pictures/* !web/images/uploaded_profile_pictures/.empty # or just !.empty 

This will make Git ignore all files in that folder except of .empty, allowing you to add the folder to the repo.

For the second question: What kind of files are missing? Are those just random ones?

Sign up to request clarification or add additional context in comments.

1 Comment

Hm... i didn't know that.. thx. Hm.. i dont think so... the missing files( dont know if all of them) was first somehow ... as submodules of git.. but than i removed all .git folders from this folders... git status is showing (clean) and pushed tham to server... but i dont know why they are missing...
2

As @Uroc327 mentioned in his comment, git doesn't handle "folders and files" but instead it uses "content".

This means that an empty folder is simply non existent to git.

This is a common problem, and the simplest solution is to add some "fake content" (an empty file) to a folder.

As @jwhy said, you could create a file named empty.
A more elegant approach (in my opinion) would be having in the folder web/images/uploaded_profile_pictures a file named .gitignore which contains the following:

* !.gitignore 

1 Comment

okay i know that now thx, but the main problem is now the missing files( dont know if all of them) was first somehow ... as submodules of git.. but than i removed all .git folders from this folders... git status is showing (clean) and pushed tham to server... but i dont know why they are missing...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.