8

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

m-ric
  • 5,621
  • 7
  • 38
  • 51
tmslnz
  • 1,801
  • 2
  • 15
  • 24
  • All globbing is custom at some level - it's shell-dependent. Presumably Mercurial provides its own version of globbing too; it wouldn't make much sense for the behavior to change depending on the user's shell. – Cascabel May 25 '10 at 16:55
  • 1
    Thanks, I've read your other answer on http://stackoverflow.com/questions/2899875/git-add-not-working-with-png-files/2900049#2900049 which helped clear things out a bit. However the comment above seems to contradict yours and VonC observation that Git reverts to whatever the user's shell glob syntax allows. Upon re-reading after your comments, the man page does in fact mention exclusion dependance on fnmatch() and the user's shell (the last two points) – tmslnz May 25 '10 at 18:16
  • I don't think it depends on the user's shell. The documentation is a little confusing there, you're right, but it's using fnmatch in either case. The documentation just uses the phrase "shell glob" as a more readable replacement for fnmatch. The code never actually invokes the user's shell. – Cascabel May 26 '10 at 13:31
  • As for the answer to the other question... the problem there was that someone was trying to use `git `, so the shell expanded the globbing *before git ever had a chance to see it*. As others pointed out, quoting the glob pattern can cause it to pass through to git, where (if the command in question supports globbing) it will be expanded by fnmatch. – Cascabel May 26 '10 at 13:32
  • Seems like a lot of the site's content over kernel.org is gone after some security breach. See the note on the homepage. – tmslnz Dec 08 '11 at 12:54

2 Answers2

3

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

Cascabel
  • 479,068
  • 72
  • 370
  • 318
  • As I mentioned in your previous answer http://stackoverflow.com/questions/2899875/git-add-not-working-with-png-files/2900049#2900049 (and as Chris Johnsen details in the same question), all pattern-based file selections are delegated to the `fnmatch()` function, isn't it. – VonC May 25 '10 at 17:54
  • Not true jefromi, `!pattern` negates a match – AD7six Jan 30 '12 at 11:25
  • @AD7six: Yes, and **gitignore patterns are not regexes**. – Cascabel Jan 30 '12 at 15:21
  • sorry, I read your answer to be pointing out the lack of exclude - not regex. – AD7six Jan 30 '12 at 15:25
  • 1
    By "There is no built-in way of excluding by regex. If there were, you'd see it on the man page" do you simply mean to say ".gitignore does not support regexes"? It's really confusing as written. – iconoclast Jun 20 '12 at 20:44
  • 1
    @iconoclast: That's essentially what I mean, yes. The way I phrased it, it also indicates that there's not another built-in mechanism *besides* the gitignore (and the other exclude files) which supports regex. – Cascabel Jun 20 '12 at 21:21
1

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!

Andrea Salicetti
  • 2,423
  • 24
  • 37
  • 1
    Not exactly *what*? Remember: your answer will not necessarily appear in the sequence it did when you initially post it, so responding to a previous answer or a comment is not a good idea. Additionally, even the question might be revised, and other answers might get deleted. – iconoclast Jun 20 '12 at 20:47