Git ignore file, git adds ignore files

Source: Internet
Author: User

The simplest method is to create a file:. gitignore in the same directory as the. Git directory.

Touch. gitignore

Vi. gitignore

: WQ

Note: If the file to be ignored has been managed by git, you need to remove it first. The command is as follows:

E.g .:

Git Rm-r -- cached webroot/WEB-INF/classes /**/*

-R: Recursion

Git commit

Then, the ignore in. gitignore takes effect.

Reference //-------------------

From:

Http://gitready.com/beginner/2009/01/19/ignoring-files.html

The easiest and simplest way is to create.gitignoreFile in your project's root directory. The files you choose to ignore here take affect for all directories in your project, unless if they include their own.gitignoreFile. this is nice since you have one place to configure ignores unlike SVN's SVN: Ignore which must be set on every folder. also, the file itself can be versioned, which is definitely good.

Here's a basic.gitignore:

$ cat .gitignore# Can ignore specific files.DS_Store# Use wildcards as well*~*.swp# Can also ignore all directories and files in a directory.tmp/**/* 

Of course, this cocould get a lot more complex. You can also add exceptions to ignore rules by starting the line!. See an example of this at the GitHub guide on ignores.

Two things to keep in mind with ignoring files: First, if a file is already being tracked by git, adding the file.gitignoreWon't stop git from tracking it. You'll need to dogit 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 be tracked, they need to have something in them. usually doingtouch .gitignoreIs enough to keep the folder tracked.

You can also open up$GIT_DIR/info/exclude($GIT_DIRIs usually your.gitFolder) and edit that file for project-only ignores. the problem with this is that those changes aren't checked in, so use this only if you have some personal files that don't need to be shared with others on the same project.

Your final option with ignoring folders is adding a per-user ignore by setting upcore.excludesfilesOption in your config file. You can set up.gitignoreFile in yourhome directory that will affect all of your repositories by running this command:

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

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

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.