git/list[1] front-page[2] threads[3] people[4] search[5] about
 

proposal for improving gitignore syntax

From
TCTimothee Cour <thelastmammoth@gmail.com>
Date
Apr 23, 2020, 08:04 UTC
Message-ID
<CANri+Ey2o-P+3S9iu1xj5YQooqBxo5Lvom0HdiQDAkSVTRv86A@mail.gmail.com>

I'm facing a common problem with gitignore, see https://stackoverflow.com/questions/61381438/how-to-gitignore-extension-less-files-without-breaking-a-global-gitignore It doesn't seem to be possible to gitignore extension-less files (eg posix binaries) without negative side effects, eg: ``` * !/**/ !*.* ``` It's more complicated than it should and also doesn't work well, as it will render a global gitignore useless.

This is just one of the problems with gitignore.

Such a common task should have an easy solution, and I'm wondering whether gitignore can be improved to make this easy/possible.

Here's a concrete proposal. If 1st line contains `# gitignore-syntax:v2`, it uses a new syntax, otherwise it uses existing syntax, to ensure backward compatibility. With the new syntax, strings enclosed inside parenthesis, eg (\w+) denote regular expressions matching a single path component, with ^$ implied for each path component to match the entire component.

Regular expressions are forbidden to span across path components. (\w+\.(md|txt)) Examples: ``` # gitignore-syntax:v2 # the line above enables the new syntax for this file

# this gitignores all extension-less files anywhere (: ([^.]+) # this un-ignores files called README !README

# this will gitignore for example /abc/foo.md /*/((foo|bar)\.md)

# this will gitignore directories (bc trailing /) like ab/cd/foo/123/ **/(\w+)/(\d+)/ ```

old tools like grep support regex so I'm assuming git could too, but if for some reason that can't work (why?), some simplified version could be supported to at least enable common cases without a full blown regex engine, for example */([^.]+)

Message 1 of 1 in “proposal for improving gitignore syntax”
  1. Timothee CourApr 23, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.