threads / discuss / 48917

Q: Ignore ./foo, but not script/foo

Subject: Q: Ignore ./foo, but not script/foo

## tl;dr

6 messages between Jul 19, 2018 and Jul 19, 2018.

replies: 5people: 4as markdown or json

Ulrich Windl· Jul 19, 2018, 07:38 UTC · lore
Hi!
I have a (simple) question I could not answer elegantly from the gitignore(5) manual page:

A project produces a "foo" binary in the root directory that I want to ignore (So I put "foo" into .gitignore) Unfortunately I found out taht I cannot have a "script/foo" added while "foo" is in .gitignore. So I changed "foo" to "./foo" in .gitignore. I can could add "script/foo", but now "foo" is not ignored any more!

Is there as solution other than:? -- foo !script/foo !bla/foo #etc. --

If "foo" is one exception to generally using foo elsewhere, it seems to be counterproductive to have to add exceptions for all the cases that are not exceptions, while "foo" is the only exception...
Did I miss something? If so, maybe add it to a future manual page.

Regards, Ulrich

3Ævar Arnfjörð Bjarmason· Jul 19, 2018, 08:01 UTC · re: Ulrich Windl · lore

Re: Q: Ignore ./foo, but not script/foo

On Thu, Jul 19 2018, Ulrich Windl wrote:
Show 14 quoted lines
> Hi!
>
> I have a (simple) question I could not answer elegantly from the gitignore(5) manual page:
>
> A project produces a "foo" binary in the root directory that I want to ignore (So I put "foo" into .gitignore)
> Unfortunately I found out taht I cannot have a "script/foo" added while "foo" is in .gitignore.
> So I changed "foo" to "./foo" in .gitignore. I can could add "script/foo", but now "foo" is not ignored any more!
>
> Is there as solution other than:?
> --
> foo
> !script/foo
> !bla/foo
> #etc.
The solution is to just do:
    echo /foo >.gitignore

Then it'll ignore the top-level /foo, but nothing else. How did you come up with this "./" syntax? It's not understood by gitignore. From gitignore(5):

   A leading slash matches the beginning of the pathname. For example,
   "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
Timothy Rice· Jul 19, 2018, 09:06 UTC · re: 3Ævar Arnfjörð Bjarmason · lore

Re: Q: Ignore ./foo, but not script/foo

> How did you come up with this "./" syntax?
It is a Unix thing: "./" or just "." refers to the current directory.

When calling scripts or programs in the current directory from a Unix command line, it is required to refer to them as, say, "./foo" (not just "foo") -- unless "." is in your PATH.

Most people do put "." in their PATH for convenience but it is considered a little unsafe [1].

Personally, I am surprised that gitignore does not understand this notation. To me, OPs meaning was crystal clear: "./foo" should mean to only ignore the foo in the repository's root directory.

[1] https://superuser.com/questions/156582/why-is-not-in-the-path-by-default
~ Tim
Konstantin Khomoutov· Jul 19, 2018, 09:22 UTC · re: Timothy Rice · lore

Re: Q: Ignore ./foo, but not script/foo

On Thu, Jul 19, 2018 at 07:06:57PM +1000, Timothy Rice wrote:
[...]
> Most people do put "." in their PATH for convenience
[...]

IMO this is a gross overstatement: personally, I know of no person using a Unix-like operation system who does this.

Ævar Arnfjörð Bjarmason· Jul 19, 2018, 09:30 UTC · re: Timothy Rice · lore

Re: Q: Ignore ./foo, but not script/foo

On Thu, Jul 19 2018, Timothy Rice wrote:
Show 16 quoted lines
>> How did you come up with this "./" syntax?
>
> It is a Unix thing: "./" or just "." refers to the current directory.
>
> When calling scripts or programs in the current directory from a Unix
> command line, it is required to refer to them as, say, "./foo" (not just
> "foo") -- unless "." is in your PATH.
>
> Most people do put "." in their PATH for convenience but it is considered a
> little unsafe [1].
>
> Personally, I am surprised that gitignore does not understand this
> notation. To me, OPs meaning was crystal clear: "./foo" should mean to only
> ignore the foo in the repository's root directory.
>
> [1] https://superuser.com/questions/156582/why-is-not-in-the-path-by-default

To clarify I was trying to fish for whether we'd accidentally documented "./" somewhere since OP was making references to the docs.

Ulrich Windl· Jul 19, 2018, 11:00 UTC · lore

Antw: Re: Q: Ignore ./foo, but not script/foo

>>> Sebastian Staudt <koraktor@gmail.com> schrieb am 19.07.2018 um 09:55 in

Nachricht <CA+xP2SZJ0VN0Y7SChAx1a8joVMKMU2R9d0je801i=9SuLicF3w@mail.gmail.com>:

Show 6 quoted lines
> Hello Ulrich,
> 
> if you want to ignore a file in the root of the repository (and only
> there) this is the correct syntax:
> 
>     /foo
Hi!
Thanks, you are perfectly right: It works, and actually, when read carefully enough, the last item in "PATTERN FORMAT" explains that.
Maybe the EXAMPLES could have an example for each item (5 cases) described ;-)

Regards, Ulrich

Show 36 quoted lines
> 
> Best regards,
>     Sebastian
> Am Do., 19. Juli 2018 um 09:45 Uhr schrieb Ulrich Windl
> <Ulrich.Windl@rz.uni-regensburg.de>:
>>
>> Hi!
>>
>> I have a (simple) question I could not answer elegantly from the 
> gitignore(5) manual page:
>>
>> A project produces a "foo" binary in the root directory that I want to 
> ignore (So I put "foo" into .gitignore)
>> Unfortunately I found out taht I cannot have a "script/foo" added while 
> "foo" is in .gitignore.
>> So I changed "foo" to "./foo" in .gitignore. I can could add "script/foo", 
> but now "foo" is not ignored any more!
>>
>> Is there as solution other than:?
>> --
>> foo
>> !script/foo
>> !bla/foo
>> #etc.
>> --
>>
>> If "foo" is one exception to generally using foo elsewhere, it seems to be 
> counterproductive to have to add exceptions for all the cases that are not 
> exceptions, while "foo" is the only exception...
>>
>> Did I miss something? If so, maybe add it to a future manual page.
>>
>> Regards,
>> Ulrich
>>
>>

← back to recent threads