There are many files that do not have to be managed with Git. For example, eclipse or other IDE-generated project files, compilation of generated targets or temporary files, etc. When you use git status, you'll see the list of these files in the untracked files, which is a long time to add (using git add). /git add-u), all these non-tracked files will be added to the index.
============ Some grumbling ============ so naturally want to tell git to ignore these files, we will certainly think of Google, enter the title of this article keyword (some people will go directly to the document), then of course there will be many solutions, Most tell us to add a list of files to be ignored in the. gitignore file; The problem is likely to persist. Again Google, this time may find help.github.com or StackOverflow, see some of the original discussion; It is important to ensure that the files are not being tracked by git before you add the ignore files to the. Gitignore, using the command git RM first- Cached filename To remove them from the index. Finally see the solution can not help but Anxi, do-hit git status to try, the problem is likely to persist. Too many Chinese "technical information" is copied, reproduced by the people themselves have not tried; slightly better in the English community to see the relevant discussions, the translation of a post, there may be understanding of the problem or ignore some of the details, leading to still can't solve the problem. So the search engine gives the Chinese result, there are a lot of useless to solve the problem. Git ignoring files is common and should be a simple question, but most of the posts don't even understand the problem, and this has sparked a series of complaints. Think more about the problem, the essence of the problem, the principle of the solution, and the most important thing is to actually do it. ============ whining over ============
Solution:
1. Local warehouse ignoredFile-ignoring rules for local warehouses can be added in the. git/info/exclude file. These ignored files are not submitted to the shared library and are therefore not shared by collaborators.
2. Current working directory Add file IgnoreFor each level of working directory, create a. gitignore file that adds files or directories to the file that you want to ignore.
but before you create and edit this file, make sure that the files you want to ignore are not added to the git index. Using commands
git rm--cached filenameRemove the files that will be ignored from the index. --Excerpt. Gitignore format specification • All blank lines or lines beginning with the comment symbol # are ignored by Git.
• Standard Glob pattern matching can be used.
• The match pattern is followed by a backslash (/) to indicate that the directory is to be ignored.
• to ignore files or directories other than the specified pattern, you can precede the pattern with an exclamation point (!). Reverse.
The so-called glob pattern refers to the simplified regular expression used by the shell. An asterisk (*) matches 0 or more arbitrary characters; [ABC] matches any one of the characters in square brackets (this example either matches a, either matches a B, or matches a C); question mark (?) Matches only one arbitrary character, if two characters are separated by a dash in square brackets, indicating that all of the two character ranges can be matched (for example [0-9] to match all 0 to 9 digits). 2.1 The directory for each level of the working directory can have a. gitignore file that describes the files or directories that need to be ignored by git in the current directory 2.2. Gitignore files can be submitted to shared libraries and shared by collaborators
3. Global. GitignoreYou can reduce the rule duplication definition for each level of the directory by creating ~/.gitignore_global and adding to the GIT global configuration. Using commands
git config--global core.excludesfile ~/.gitignore_globalCan. gitignore_global File Sample Ruby code
- <span style="Font-size:small;" ># Compiled Source #
- ###################
- *.com
- *. class
- *.dll
- *.exe
- *.o
- *.so
- # Packages #
- ############
- # it ' s better to unpack these files and commits the raw source
- # git has it own built in compression methods
- *.7z
- *.dmg
- *.gz
- *.iso
- *.jar
- *.rar
- *.tar
- *.zip
- # Logs and Databases #
- ######################
- *.log
- *.sql
- *.sqlite
- # OS generated Files #
- ######################
- . Ds_store
- . Ds_store?
- ._*
- . spotlight-v100
- . Trashes
- Icon?
- Ehthumbs.db
- Thumbs.db
- </span>
References:
1. Ignoring files, Https://help.github.com/articles/ignoring-files2. The initial use of git-ignores certain files, http://www.phperblog.net/?p=1733. git ignore file, Git adds ignore files, http://www.cnblogs.com/wucg/archive/2011/08/16/2141647.html
GitHub ignores file Setup experience