Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in DevOps and Agile by (19.7k points)

What is the proper syntax for the .gitignore file to ignore files in a directory?

Would it be

config/databases.yml

cache/*

log/*

data/sql/*

lib/filter/base/*

lib/form/base/*

lib/model/map/*

lib/model/om/*

or

/config/databases.yml

/cache/*

/log/*

/data/sql/*

/lib/filter/base/*

/lib/form/base/*

/lib/model/map/*

/lib/model/om/*

?

closed

1 Answer

+1 vote
by (62.9k points)
selected by
 
Best answer

PATTERN FORMAT

  • A blank line matches no files, thus it will serve as a separator for readability.

  • A line starting with # is a comment.

  • An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern can become included again. If a negated pattern matches, this can override lower precedence patterns sources.

  • If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find a match with a directory. In alternative words, foo/ will match a directory foo and paths underneath it, but will not match a regular file or a symbolic link foo (this is consistent with the approach how pathspec works in general in git).

  • If the pattern doesn't contain a slash /, git treats it as a shell glob pattern and checks for a match against the pathname relative to the location of the .gitignore file (relative to the top level of the work tree if not from a .gitignore file).

  • Otherwise, git treats the pattern as a shell glob appropriate for consumption by fnmatch(3) with the FNM_PATHNAME flag: wildcards within the pattern won't match a / in the pathname. For example, Documentation/*.html matches Documentation/git.html however not Documentation/ppc/ppc.html or tools/perf/Documentation/perf.html.

  • A leading slash matches the start of the pathname. For example, /*.c matches cat-file.c but not mozilla-sha1/sha1.c.

You can find more here

git help gitignore

or

man gitignore

.gitignore example - How do I ignore files in a directory in Git?
Intellipaat-community
by (19.7k points)
Very well Explained!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...