Some files are ignored when git submits a project.

Source: Internet
Author: User
Tags glob

In general, some files do not need to be managed by git, and we do not want them to appear in the list of untracked files. Generally, these files are automatically generated, such as log files or temporary files created during compilation. You can create a file named. gitignore to list the file modes to ignore. Let's look at a practical example:

$ cat .gitignore*.[oa]*~

The first line tells git to ignore all files ending with. O or.. Generally, such object files and archive files are generated during compilation, so we do not need to track their versions. The second line tells git to ignore all (~). Many text editing software (such
Emacs) saves copies with such file names. In addition, you may need to ignore the log, TMP or PID directory, and automatically generated documents. You need to develop the habit of setting up. gitignore files from the beginning, so as not to mistakenly submit such useless files in the future.

The format of file. gitignore is as follows:

  • All blank lines or lines starting with '#' are ignored by git.
  • You can use the standard glob pattern matching.
  • The matching mode is followed by the backslash (/) Indicates the directory to be ignored.
  • To ignore files or directories other than the specified mode, you can add an exclamation point before the mode (!.

The so-called glob mode refers to the simplified regular expression used by shell. Asterisk (*) Matches zero or multiple arbitrary characters;[abc]Match any character in square brackets (in this example, either
A, either matching a B or a C); Question mark (?) Matches only one arbitrary character. If two characters are separated by a short line in square brackets, it means that all the characters within the two character ranges can match (for example[0-9]Match All
0 to 9 ).

Let's look at an example of the. gitignore file:

# This is a comment-it will be ignored by git *. A # All files ending with. A will be ignored! Lib. A # But Lib. except for a/todo # ignore only the todo files under the project root directory, excluding subdir/todobuild/# ignore all files under the build/directory DOC /*. TXT # DOC/notes.txt is ignored, but Doc/Server/arch.txt is not included.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.