Git ignore, gitignore

Source: Internet
Author: User

Git ignore, gitignore

 

Reprinted: http://blog.csdn.net/benkaoya/article/details/7932370

Three methods for ignore files:

# A row starting with '#' is considered as a comment.

# Ignore all objects whose names are foo.txt.

Foo.txt

# Ignore all generated html files,

*. Html

# Foo.html is manually maintained, so the exception is.

! Foo.html

# Ignore all. o and. a files.

*. [Oa]

 

Method 1]

 

Create a file named. Gitignore'sFile (because it starts with a dot and has no file name, it cannot be directly created in the windows directory. You must right-click Git Bash and create a file in linux.. GitignoreFile ). As shown in.

 

The. gitignore file is valid for its directory and all subdirectories in the directory. By adding the. gitignore file to the repository, other developers update the file to the local repository to share the same set of ignore rules.

 

Method 2]

 

Ignore the file by configuring the. git/info/exclude file. This method is globally effective for the repository and can only be used for the local repository. Others cannot share the ignore rules in this way unless others modify the file in the local repository.

 

Method 3]

 

Use the core. Excludesfile option of the. git/config configuration file to specify a file that ignores the rule (full path), as shown in. The ignore rules are in the file e:/gitignore.txt (of course, the file name can be arbitrary ).

 

[Example]

 

# Ignore *. o and *. a files

 

*. [Oa]

 

# Ignore *. B and *. B files, except my. B.

 

*. [BB]

 

! My. B

 

# Ignore dbg files and dbg Directories

 

Dbg

 

# Ignore only the dbg directory and not the dbg file

 

Dbg/

 

# Ignore only the dbg file and not the dbg directory

 

Dbg

 

! Dbg/

 

# Only the dbg files and directories under the current directory are ignored. The dbg of the subdirectory is not within the ignore range.

 

/Dbg

 


Git ignores file help

I recommend you use TortoiseGit. It is very convenient to operate. You just need to right-click the ignore directory and add it. Then a gitignore file will be generated in the project.

Then you open this. gitignore and you will see/bin. Using this as a template, you can also directly add other directories to it.



Git Problems

Because you fail to checkout. 1.txtand 2.txt are not deleted in the git repository in your above operations. During checkout, git checks that you still have uncommitted changes, so an error is returned.

In step 2 of LZ operations, you should use git rm 1.txtto submit the changes later. Otherwise, gitwill only submit the 2.txt changes to the repository. In addition, after deleting 2.txt, you still need to submit it before checkout.

It is recommended that LZ check the prompts provided by git after each operation, such as whether the operation is successful and which files are submitted. These prompts are helpful.
Please adopt.
 

Related Article

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.