From: Junio C Hamano <email@example.com> To: Maris Razvan <firstname.lastname@example.org> Cc: email@example.com, Jonathan Nieder <firstname.lastname@example.org> Subject: Re: Gitignore documentation Date: Mon, 14 Jan 2019 10:47:44 -0800 Message-ID: <email@example.com> (raw) In-Reply-To: <CALZbgSQti+t2dA4nm+DCDGxQjsvNJy3UDdqAya16v+Mv5O4Xdw@mail.gmail.com> Maris Razvan <firstname.lastname@example.org> writes: > I was reading the gitignore documentation > (https://git-scm.com/docs/gitignore), especially the following > paragraph: > > "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)." > > From that paragraph I understand that if I have the following > directory structure: > > .gitignore > a > f > > (the root of the repository contains the file .gitignore and the > folder a, while the file f is inside folder a) > where the file .gitignore contains only the pattern f, when file "f" > is tested whether it should be ignored or not, the pattern f in > .gitignore is matched against the "pathname relative to the location > of the .gitignore file" (which is a/f). Because "f" (the pattern) does > not match "a/f" (the pathname relative to the location of .gitignore), > the file "f" should not be ignored. However, if I test this scenario, > git ignores the file (this behaviour is consistent with the examples > from the rest of the documentation and other explanations on the > internet). > > I looked at the history of the "Documentation/gitignore.txt" file on > the github repository and I saw that initially the paragraph looked > like this: > > "If the pattern does not contain a slash '/', git treats it as > a shell glob pattern and checks for a match against the pathname > without leading directories." > > This old version of the paragraph is consistent with git's current behaviour. > > Then I saw the following commit > https://github.com/git/git/commit/81c13fde379c46cad6b6e4a03ed7ee4f686c030f#diff-7fea460d44f92f185e7add8aa5620305, > which changed that paragraph to the current version. > However, I cannot see how the two wordings (the original one and the > current one) are the same. Thanks. Jonathan, after re-reading 81c13fde ("gitignore.5: Clarify matching rules", 2010-03-05), I do not recall why we thought this part of the change was a good idea, either. Patterns with slash is anchored at one directory, and that directory is the one that has per-directory .gitignore file. Patterns without slash (including a pattern that ends with but otherwise has no other slash) are supposed to match at every level below the directory that the pattern is defined in. Documentation/gitignore.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt index 1c94f08ff4..bf1182169e 100644 --- a/Documentation/gitignore.txt +++ b/Documentation/gitignore.txt @@ -98,9 +98,7 @@ PATTERN FORMAT - 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). + pathname without leading directories. - Otherwise, Git treats the pattern as a shell glob: "`*`" matches anything except "`/`", "`?`" matches any one character except "`/`"
next prev parent reply index Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-12 20:16 Maris Razvan 2019-01-14 18:47 ` Junio C Hamano [this message] 2019-01-14 21:38 ` Jonathan Nieder 2019-01-14 21:52 ` Junio C Hamano 2019-01-15 9:27 ` Duy Nguyen
Reply instructions: You may reply publically to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
firstname.lastname@example.org list mirror (unofficial, one of many) Archives are clonable: git clone --mirror https://public-inbox.org/git git clone --mirror http://ou63pmih66umazou.onion/git git clone --mirror http://czquwvybam4bgbro.onion/git git clone --mirror http://hjrcffqmbrq6wope.onion/git Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.version-control.git nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git nntp://news.gmane.org/gmane.comp.version-control.git note: .onion URLs require Tor: https://www.torproject.org/ or Tor2web: https://www.tor2web.org/ AGPL code for this site: git clone https://public-inbox.org/ public-inbox