Information Technology Reference
In-Depth Information
If your project contains some files that are automatically generated, you should prob-
ably ignore them. The best way to do this is to create a special file named
.gitig-
nore
. The file should contain the patterns to be ignored by git. As a result, if you com-
mit the file into your repository, all your colleagues working on the same project will
share the rules.
The rules stored in
.gitignore
are the following.
• If the rule starts with a slash
/
it will match only the entries that are stored
in the root directory of your project. The rule
/foo
will only match the
file
/foo
it will not match the file
some/dir/foo
.
• If the rule ends with a slash
/
it will match only the directories. Thus
the rule
bar/
will match the directories
bar/
and
some/other/dir/
bar/
but it will not match the file
some/special/bar
.
You can use
.gitignore
files on a per directory basis. The
.gitignore
file
stored within a directory will affect this directory and its subdirectories.
Three types of settings
The patterns for files that should be ignored can be defined on three different levels:
•
.gitignore
—this file is committed into the directory; it affects only
the repository in which it is committed.
• Global
.gitignore
—this file resides in your home directory. It affects
all of your repositories. This is your private file: you do not commit this
file into the repository.
•
.git/info/exclude
—this file is stored in .git directory; it is your
private file—you do not share it with others. The
exclude
file affects
only one repository: the one that contains the file.
How to clean a project that contains ignored files?
If the repository contains ignored files you can remove all the tracked files with:
$ git ls-files | xargs rm