Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusing .gitignore syntax

I was reading http://www.kernel.org/pub/software/scm/git/docs/v1.7.10/gitignore.html and the 6 points used to explain the ignore patterns seem to be describing a custom variant of a glob search syntax. I am more familiar with Mercurial, which allows to explicitly ignore via glob or regex patterns, no questions asked.

  • Is there any similar functionality in Git?
  • Can anyone point me to some more exhaustive reference than the Git man page?

Best,
t

like image 352
tmslnz Avatar asked May 25 '10 16:05

tmslnz


People also ask

What should I ignore in Gitignore?

A . gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track. Inside . gitignore , you can tell Git to ignore only a single file or a single folder by mentioning the name or pattern of that specific file or folder.

What is the format of Gitignore?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

How do I ignore all .ENV files?

You should use your . gitignore file to ignore the . env file.

What does double asterisk mean in Gitignore?

A trailing " /** " matches everything inside. For example, " abc/** " matches all files inside directory " abc ", relative to the location of the .gitignore file, with infinite depth. A slash followed by two consecutive asterisks then a slash matches zero or more directories.


2 Answers

There is no built-in way of excluding by regex. If there were, you'd see it on the man page.

like image 110
Cascabel Avatar answered Sep 21 '22 05:09

Cascabel


Not exactly. It can be used a bash-like syntax where you can specify something like this:

*tmp_*~

which is the same as the regExp: .*tmp_.*~

Hope this will help you!

like image 39
Andrea Salicetti Avatar answered Sep 19 '22 05:09

Andrea Salicetti