0

What is/are the difference(s) when writing this in .gitignore:

/tmp/*
/tmp
/tmp/

I noticed that if I create a folder tmp, no matter what I write in my .gitignore it does not appear when I do git status. What is the difference between those three, and what should I write if I want the folder to be commited, but not the files within it.

StarTrek18
  • 323
  • 4
  • 15
  • As I recall, git works on per-file basis and `clone` will not create empty directories. Would like to be proven wrong. – keltar Mar 28 '14 at 17:55
  • That is my understanding as well. Git does not track empty directories. – Bart Mar 28 '14 at 18:17
  • Interesting. So, if the directory is needed in a project, and I want other users to have it. What is the solution? I mean, I want to share the structure of my app, but not the files within that folder. – StarTrek18 Mar 28 '14 at 18:38
  • Add dummy file. `.gitignore` as shown in answer, or anything else that you wouldn't use. Or make your build system (if you use one, e.g. `make`) create these directories. – keltar Mar 28 '14 at 18:41

1 Answers1

2

git does not track empty folders, thus if it thinks nothing is inside of it, it won't add it. One solution to your problem would be instead of adding /tmp/* to your global .gitignore file, put one into the /tmp/ folder, just containing

*
!.gitignore

and commit this file. In this way, /tmp/ won't be empty to git and thus be added to the repository, but no further files would be.

Andreas Wiese
  • 718
  • 3
  • 8