Git has a long history as a code management tool for team project development, and it also brings great convenience to team project management.

Developers who have used Git for project code management will find a.gitignore file in the root directory of their project, which contains several directories. Beginners must feel confused, what is this? Why here? I didn’t use it in the project… Strange!!

    .DS_Store
    node_modules/
    dist/
    npm-debug.log
    yarn-error.log
    .idea/
Copy the code

Next, we will give a good introduction:

You can refer to https://git-scm.com/docs/gitignore

describe

According to the website

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.

Git ignores some special files based on the configuration of this file. These files are not intended to be overwritten, but will not work if they are already tracked by Git.

Configuration rules

  • 1. A directory starts with a slash (/).

  • 2. Use asterisk (*) to wildcard multiple characters.

  • 3. Begin with a question mark? Wildcard single character

  • 4. Contain a single character matching list in square brackets “[]”;

  • 5, with the exclamation mark “!” It does not ignore (trace) matched files or directories.

Git matches the.ignore configuration file from top to bottom, meaning that if the previous rule matches a larger range, the later rule will not take effect.

Example is given to illustrate

    .DS_Store
    node_modules/
    **/dist/
Copy the code

The configuration above, from top to bottom, matches the.ds_store file, matches the entire node_modules directory, and matches the dist directory in any directory.

Of course these directories and files are configured relative to the location of the.gitignore file.

Pay attention to

  • 1, for the whole team, the file configuration files and directories are relative to the whole team, do not affect the team’s code management, otherwise the gain is not worth the loss.

  • 2. Perform proper configuration based on the configuration rules