.gitignore file


Official website in different languages .ignore:

https://github.com/github/gitignore/tree/main


rule

basic rules

  • Use #as comment
  • In .gitignorea file, each line represents a pattern;
  • Empty lines do not match any files;
  • git tracks files, not directories;
  • .gitignoreEven setting ignore in has no effect if the local repository file is already tracked .
  • .gitignoreThe files will also be uploaded to the remote warehouse, so people in the same warehouse can use the same .gitignorefile.

ignore files and directories

folderName
  • Indicates that the folderName file and folderName directory are ignored, and src/folderthe files and src/utils/folderfiles will be ignored, that is, they will not be submitted to the remote warehouse.
  • Will automatically search multi-level directories, such as: */*/folderName.

Ignore folderName files only, not folderName directories (!)

The schema looks like this:

folderName
!folderName/
  • Reverse operation !: Indicates that the previously ignored matching pattern is included in the trace content again.
  • src/folderName files, src/utils/folderName files will be ignored, and folderName directories with the same name will not be ignored.

just ignore the directory /

folderName/

Ignore folderName directories, including:

  • The foldernName under the current directory, for example: folderName/;
  • folderName under the multi-level directory, for example: */*/folderName/;
  • src/folder files and src/utils/folder files with the same name are not ignored.

Use wildcards * ? []

Commonly used wildcards are:

  • Asterisk *: match multiple characters;
  • Question mark ?: match any character /except ;
  • Square brackets [xxxx]: match characters in multiple lists;
$ tree
.
├── src
│   ├── add.c
│   ├── add.i
│   └── add.o
├── test.c
├── test.i
└── test.o

1 directory, 6 files

Among them, the contents of the .gitignore file are as follows:

*.[io] 
  • So in the local warehouse, test.ifile, test.ofile, src/add.ofile, src/add.ifile will be ignored
  • test.cFiles and files are not add.cignored.
  • The matching patterns ignored here are multi-level directories.

Multi-level directory**

A slash followed by two consecutive asterisks **indicates a multi-level directory.

src/**/file 

It can mean ignore src/folder1/file, src/folder1/folder2/***/foldern/fileetc.


2023-07-29 (Sat)

Guess you like

Origin blog.csdn.net/lovechris00/article/details/131992991