gitignore binary files that have no extension

前端 未结 18 1190
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 02:14

How can binary files be ignored in git using the .gitignore file?

Example:

$ g++ hello.c -o hello

The

18条回答
  •  渐次进展
    2020-11-28 02:30

    .gitignore uses glob programming to filter files, at least on Linux.

    I am about to give a coding talk at a Meetup and, in preparation, I made a directory with several subdirectories that are named according to the order I want to present them: 01_subject1, 02_subject2, 03_subject3. Each subdirectory contains a source file with a language-dependent extension that compiles to an executable file whose name matches the source file name without the extension according to common practice.

    I exclude the compiled files in the numeral-prefixed directories with the following .gitignore line:

    [0-9][0-9]_*/[!\.]*

    According to my understanding of the documentation, it shouldn't work. Having the trailing asterisk should fail because it should match any number of unspecified characters, including the '.' + extension. Omitting the trailing asterisk should fail (and does) because [!\.] matches only a single non-period character. However, I added the trailing asterisk, as I would for a regular expression, and it works. By work, I mean that git notices changes to the source file, but not the existence or changes to the compiled files.

提交回复
热议问题