# Newbie .gitignore problem

2 messages from 2010-09-22 to 2010-09-22. Participants: Jonathan Gossage, Kevin Ballard.
Thread: https://gitlist.dev/t/25199

## Jonathan Gossage, 2010-09-22 16:41

Subject: Newbie .gitignore problem
Message-ID: <AANLkTin=BwgjqWQ3NfNdL9a1fUnVnFMrmAsmnZjHS=gL@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTin%3DBwgjqWQ3NfNdL9a1fUnVnFMrmAsmnZjHS%3DgL%40mail.gmail.com

```
I am having a problem specifying .gitignore filters properly
I have a directory structure as follows:

          repo-root
               |
               -------------------------------------------------------------------
               |                    |
           |
              dir1               dir2  (symlink)
             dir3
                                    |
                ---------------------------------------------------
               |                                                   |
          many directories and files                  dir4

My problem is that I want to exclude all files and sub-directories in dir2
except for dir4 from control by Git.
I tried a number of variations on the following .gitignore file in dir2 but
either everything was excluded or everything was included. I tested using
git add -uall -n

The final .gitignore file was
*
*/*
!dir4


How should I go about tackling this. The .gitignore man pages were
unclear to me.

Jonathan Gossage

```

## Kevin Ballard, 2010-09-22 19:44

Subject: Re: Newbie .gitignore problem
Message-ID: <069C161A-4498-4D4F-BEC4-800BC2A4989A@sb.org>
URL: https://gitlist.dev/e/069C161A-4498-4D4F-BEC4-800BC2A4989A%40sb.org
In-Reply-To: <AANLkTin=BwgjqWQ3NfNdL9a1fUnVnFMrmAsmnZjHS=gL@mail.gmail.com>

```
Git tracks symlinks the same way it tracks files. It'll record the contents of the symlink (the path it points to) as a blob, and then record the symlink itself with a special mode to indicate that it is a symlink. This means that if your symlink points outside of the repository, nothing pointed to by it will even be examined by git. And if it symlinks another dir in the repo, but the contents of that dir are excluded via your gitignore, anything inside the dir will still be excluded. With this in mind, it appears from your diagram that dir2 is likely to be pointing outside of the repository, and so dir4 is never even seen by git.

-Kevin Ballard

On Sep 22, 2010, at 9:41 AM, Jonathan Gossage wrote:

> I am having a problem specifying .gitignore filters properly
> I have a directory structure as follows:
> 
>           repo-root
>                |
>                -------------------------------------------------------------------
>                |                    |
>           |
>               dir1               dir2  (symlink)
>              dir3
>                                     |
>                 ---------------------------------------------------
>                |                                                   |
>           many directories and files                  dir4
> 
> My problem is that I want to exclude all files and sub-directories in dir2
> except for dir4 from control by Git.
> I tried a number of variations on the following .gitignore file in dir2 but
> either everything was excluded or everything was included. I tested using
> git add -uall -n
> 
> The final .gitignore file was
> *
> */*
> !dir4
> 
> 
> How should I go about tackling this. The .gitignore man pages were
> unclear to me.
> 
> Jonathan Gossag--
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> e

```
