Git uses the-.gitignore file (to keep some files from being uploaded to Git)

Source: Internet
Author: User
Tags glob regular expression

In general, we always have some files that don't need to be managed by Git and don't want them to always appear in the list of non-tracked files. These are usually auto-generated files, such as log files, or temporary files created during compilation. We can create a file named. Gitignore, which lists the file modes to ignore.
Here's how to create this file, first open the terminal and then enter the following command at the terminal:

CD/DVD///switch to Desktop
touch. Gitignore///    Create. Gitignore
vim. Gitignore///     enter edit. Gitignore


Enter edit mode below:

The commands to exit edit mode are:
Press ESC to exit edit mode first
Then enter: Wq Colon is also entered, and then enter to exit the edit.
This creates a. gitignore file, which is placed in the same location as the. Git hidden folder. Here are some of the Gitignore files to share:

(1) All empty lines or lines beginning with the comment symbol # are ignored by Git.
(2) The standard glob pattern matching can be used.
(3) The matching mode is followed by a backslash (/) to indicate that the directory is to be ignored.
(4) to ignore files or directories other than the specified pattern, you can add an exclamation point (!) in front of the pattern to reverse it.
The so-called glob pattern refers to the simplified regular expression used by the shell. The asterisk (*) matches 0 or more arbitrary characters, and [ABC] matches any character in square brackets (this example either matches a, matches a B, or matches a C); The question mark (?) matches only one arbitrary character; If you use a dash to separate two characters in square brackets, Indicates that all of the two character ranges can be matched (for example [0-9] to match all numbers from 0 to 9).

# This is a comment – will be ignored by Git
*.a       # ignores all. A end-of-file
!lib.a    # but LIB.A except
/todo     # simply ignores the TODO file under the project root, not including subdir/ TODO
build/    # ignores all files under the build/directory
Doc/*.txt # ignores Doc/notes.txt but does not include Doc/server/arch.txt
some of the following people will encounter add this file, found that the ignored files are still uploaded.

Reason:
This file already exists in the Git repository, which was previously submitted by push.
. gitignore files work only on files that have not yet been added to version management, and if you have previously incorporated these files into the repository with git, it won't work.
Solve:
You need to delete the file in the GIT library and update it.
Then git status again to view the status, the file no longer shows the status.

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: info-contact@alibabacloud.com 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.