0

Find below two quotes from this link:

1) In DESCRIPTION:

  • Patterns read from the command line for those commands that support them.

2) In PATTERN FORMAT (emphasis is mine):

  • If the pattern does not contain a slash /, Git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the toplevel of the work tree if not from a .gitignore file).

Both quotes (the second one in bold characters above) seem to refer to a git ignore command (not a file) which is mentioned in this answer in SO. The problem that I see here, is that this command is not even mentioned in the Pro Git book. Thus, it may be that my interpretation about the quotes above is just wrong.

I have another question about the .gitignore file and this is about this comment in SO, that I repeat below:

You can put .gitignore anywhere in a git project - if a path starts with /, it will be relative to the location of the .gitignore file; otherwise it will refer recursively to files in the current directory and its descendant directories.

I just can't see how to deduce this from the link given above.

Community
  • 1
  • 1
John Kalane
  • 1,163
  • 8
  • 17
  • About your second question - here is an extract from the link you've provided yourself: `Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.` – ingenious May 14 '16 at 18:28
  • The git ignore command in the answer you've referenced is not part of git. In the very same answer there is a link to the repository from which you can obtain the command. – ingenious May 14 '16 at 18:31
  • @ingenious In reference to the extract you provided above, I have to say that I didn't understand it at all, and because of that I can't see the relationship between this and the comment by the OP, that I referred to in my question. Maybe you could provide an answer explaining in more detail what this extract is all about. Thanks. – John Kalane May 14 '16 at 18:35
  • @ingenious `The git ignore command in the answer you've referenced is not part of git` But than, what are those two quotes referring to, if not to this command? – John Kalane May 14 '16 at 18:36

1 Answers1

0

OK, so there seems to be some misunderstanding. The article over at the pro git site about gitignore does refer to the .gitignore file, and not to the command. The command referred to in the other question is not part of git, but of a package called git extras instead.

After giving it some more thought I thnink I'm starting to get what's confusing here. You've just quoted (a part) the order in which git evaluates ignore patterns. On the very top of this order are patterns from the command line. These are all built-in and custom (like in the referenced answer) commands that handle git ignore patterns.

The second quote is probably best explained by the examples at the bottom of the gitignore manpage. I'm talking about:

$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
# Documentation/gitignore.html
# file.o
# lib.a
# src/internal.o
[...]
$ cat .git/info/exclude
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated html files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git status
[...]
# Untracked files:
[...]
# Documentation/foo.html
[...]

It is also perfectly valid to place the gitignore file anywhere in your project, please refer to the official documentation on gitignore again:

Git normally checks multiple sources, with the following order of precedence, from highest to lowest:
- command line
- a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

And the part about the leading slash is described in the following paragraph:

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".

To put it another way, a pattern is normally evaluated as a glob followed by the pattern and will match any path in any subdirectory relative to the location of the .gitignore file. However if the pattern starts with a slash, it means that the pattern matches exactly from the beginning of the relative pathname.

ingenious
  • 966
  • 10
  • 20
  • I'm convinced that the two quotes in my question have nothing to do with the **git ignore** command and I thank you for that. But I still don't understand how one could deduce the result in the [linked comment]{http://stackoverflow.com/questions/4308610/how-to-ignore-certain-files-in-git#comment43965500_4308628} in SO, from the gitignore manpage. – John Kalane May 14 '16 at 19:03