git ignores file configuration

Source: Internet
Author: User
Tags comments glob ranges regular expression tmp folder root directory git commands
1. Local warehouse ignored


File-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.


# git ls-files--others--exclude-from=.git/info/exclude
# Lines that start with ' # ' is comments.
# for a project mostly in C, the following would is a good set of
# Exclude patterns (uncomment them if you want to use them):
# *. [OA]
# *~
2. Current working directory Add file Ignore


For 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.
Use the command git RM--cached filename to remove files from the index that will be ignored.


--Excerpt. Format specification for Gitignore


• 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, or matches a B, or matches a C);
Question mark (?) Match only one arbitrary character;
If you use a dash to separate two characters in square brackets, all of the two character ranges can be matched (for example [0-9] to match all 0 to 9 digits).


2.1 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. Gitignore


You can reduce the rule duplication definition for each level of the directory by creating ~/.gitignore_global and adding to the GIT global configuration.
Use the command git config--global core.excludesfile ~/.gitignore_global


Examples of. gitignore_global files
Copy Code
Copy Code
# 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
Copy Code
Copy Code
The format specification for file. Gitignore is as follows:


• 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, or matches a B, or matches a C);
Question mark (?) Match only one arbitrary character;
If you use a dash to separate two characters in square brackets, all of the two character ranges can be matched (for example [0-9] to match all 0 to 9 digits).


Let's look at another example of a. gitignore file:


# This is a comment – will be ignored by Git
*.A # ignores all files ending with. A
!LIB.A # but except LIB.A
/todo # simply ignores the TODO file under the project root directory, excluding Subdir/todo
build/# ignores all files in the build/directory
Doc/*.txt # ignores Doc/notes.txt but does not include Doc/server/arch.txt
Copy Code
Things to keep on mind with ignoring files:


First, if a file is already being tracked by Git, adding the file to. Gitignore won ' t stop Git from tracking it.


You'll need to does git rm--cached <file> to keep the file in your tree and then ignore it.


Secondly, empty directories do not get tracked by Git.


If you want them to being tracked, they need to has something in them.
Usually doing a touch. Gitignore is enough to keep the folder tracked.


You can also open up $GIT _dir/info/exclude ($GIT _dir is usually your. GIT folder) and edit this file for Project-only Igno Res.
The problem with this is a those changes aren ' t checked in,
So, if you have some personal files, that don ' t need-to is shared with others on the same project.


Your final option with ignoring folders are adding a per-user ignore by setting up Acore.excludesfiles option in Your confi G file.
You can set up a. gitignore file in Yourhome directory, that would affect all of the your repositories by running this command:


git config--global core.excludesfile ~/.gitignore


Read up on the manpage if you ' d as-learn more about what ignores work.
As always, if you have a ignore-related tips let us know in the comments.





There are three ways git ignores files:




1, the global scope of valid ignore file


Is "version Coogan directory/.git/info/exclude", all ignore rules in the global scope are written in this file by the behavior unit;




2, the local scope of the effective ignore file


That is. gitignore, this ignore file is only valid for ignoring files in one level of directory;
If there are files in a directory that need to be ignored, you can create an ignore file in that directory. Gitignore,
And in this ignores the file to write the ignore rule, in the behavior unit, a rule occupies one line;
A special case is to create a ignore file at the root of the repository. Gitignore, at this time,
this. Gitignore ignoring files is valid for files in the version Coogan directory, and is equivalent to ignoring files at the global scope. Git/info/exclude;




3, manually specify a ignore file,


The rules and syntax in the ignore file are consistent with the first two, whichever level of the directory can be, just add the corresponding path;
The command to manually specify the Ignore file is:
git config--global core.excludesfile/path/to/.gitignore
Then manually create the ignore file in the corresponding location. Gitignore, and write the ignore rule in the file;




Note:
The content format and syntax of these three range-level ignored files are consistent;





The. Gitignor file can also be added to the project repository like any other file (directly with Git Add. Gitignore and Git commit commands),


This allows other developers in the project to share the same set of ignore file rules.





If you want to even ignore the. gitignore file yourself. Same reason, just add the. Gitignore to the file.





If you want to ignore rules that only work for a particular warehouse, you can write them down to your warehouse.





. git/info/exclude file, or write in git config variable





The file specified in the Core.excludesfile.





Some git commands can also specify ignore rules in command-line arguments, which you can use here: Gitignore view for detailed usage.





Copy Code
Version control is not added to GitHub. Gitignore settings
JAN 19TH, 2012
On GitHub page these days, because the _site folder is generated when you test locally with Jekyll,
So you need to exclude this folder to submit to GitHub, exactly how to set it.


This requires the use of. Gitignore, which is not added to version control, is established under the Git root directory. Gitignore, set as follows:


Tmp.txt//Ignore Tmp.txt
*.log//Ignore all log files
tmp/*//Ignore TMP folder all files
Log/**/*.log//Ignore all log files under the log directory including subdirectories
Some of the other filtering conditions


。 : Represents any one character
*: Represents any number of characters
{!ab}: Must not be of this type
{AB,BB,CX}: Represents any type in AB,BB,CX
[ABC]: represents any one character in A,b,c
[^ABC]: representative must not be any character in A,b,c
Because Git does not add an empty directory, the following practices cause TMP to not exist


tmp/*//Ignore TMP folder all files
Change the method, under TMP also add a. Gitignore, the content is


*
!. Gitignore
In another case, it is already committed, and then adding Gitignore is invalid, so you need to delete the cache


git rm--cached Ignore_file
This will be OK.

Copy Code


Article transferred from http://www.cnblogs.com/shangdawei/archive/2012/09/08/2676669.html

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.