git and empty directories

268 views
Skip to first unread message

Pete Yandell

unread,
Nov 26, 2007, 10:59:21 PM11/26/07
to Ruby on Rails Oceania
Just playing with git after being inspired by RailsCamp (what a
blast...great to meet all the interstate folks!) and I've noticed that
it doesn't commit empty directories, or directories that it considers
empty thanks to files it's ignoring. That means my Rails log and tmp
directories get left out, which is a bad thing.

Anyone know if there's a simple way around this?

Pete
http://notahat.com/

Tim Lucas

unread,
Nov 26, 2007, 11:09:43 PM11/26/07
to rails-...@googlegroups.com

Yep... just touch an empty .gitignore inside the directory is the
workaround.

I followed the archived long git thread around why it doesn't index
empty directories... there's a reason... but it also came down to
those wanting it never contributed a solution (though linus did help
with stubbing out an approach w/ code).

-- tim

Pete Yandell

unread,
Nov 27, 2007, 5:49:30 AM11/27/07
to Ruby on Rails Oceania


On Nov 27, 3:09 pm, Tim Lucas <t.lu...@toolmantim.com> wrote:
> On 27/11/2007, at 2:59 PM, Pete Yandell wrote:
>
> > Just playing with git after being inspired by RailsCamp (what a
> > blast...great to meet all the interstate folks!) and I've noticed that
> > it doesn't commit empty directories, or directories that it considers
> > empty thanks to files it's ignoring. That means my Rails log and tmp
> > directories get left out, which is a bad thing.
>
> > Anyone know if there's a simple way around this?
>
> Yep... just touch an empty .gitignore inside the directory is the
> workaround.

Thanks Tim. That works for empty directories, but...

For a directory like tmp I don't want an empty .gitignore; I want
a .gitignore of "*" so nothing in there gets added to repository.

Problem is, putting "*" in the .gitignore file inside tmp makes git
ignore the .gitignore file, and thus treat the directory as empty, and
thus leave it out of the repository - and I'm back to square one.

- Pete

Clifford Heath

unread,
Nov 27, 2007, 6:47:07 AM11/27/07
to rails-...@googlegroups.com

Can you ignore "[^.]*" instead?

Clifford Heath.

Pete Yandell

unread,
Nov 27, 2007, 7:44:06 AM11/27/07
to rails-...@googlegroups.com

My read of the man page said the globbing wasn't that smart, but I
just tried it and it worked.

Thanks Cliff.

- Pete

Nick Poulden

unread,
Dec 15, 2007, 11:33:44 AM12/15/07
to Ruby on Rails Oceania
Hi all,

Here's a handy snippet for touching a .gitignore file in all empty
directories except the .git folder itself:

find . \( -type d -empty \) -and \( -not -regex ./\.git.* \) -exec
touch {}/.gitignore \;

Thanks,

Nick Poulden
http://www.midlandswebdesign.com
Reply all
Reply to author
Forward
0 new messages