Al Lelopath
Al Lelopath

Reputation: 6778

add files with period in name to .gitignore

I have a problem with creating some entries for the .gitignore file. There are directories with . in their names, like so:

Thing1.This/bin  
Thing1.That/bin 
Thing1.TheOther/bin  

I want to exclude the bin directories. These directories can be added explicitly, but there are a lot which would make this tedious. I also tried using both these lines, but neither of them worked either:

*/bin
[Bb]in

How can this be specified?

I'm working on Windows 7.

Upvotes: 0

Views: 2480

Answers (2)

1615903
1615903

Reputation: 34800

If you want to add bin directories in any subdirectory to gitignore, you can use this syntax:

**/bin/

It ignores all bin folders in repository. From the docs:

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

Upvotes: 2

Jonathan Leffler
Jonathan Leffler

Reputation: 754500

I ran:

$ for number in $(seq 1 9); do mkdir -p Thing$number.Thing/bin; done
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$ 

There is no content in the directories, so there's nothing for git to track, so they are not listed as needing to be tracked. I added files to the directories:

$ for d in Thing?.Thing/bin; do cp qs.c $d; done
$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   Thing1.Thing/
#   Thing2.Thing/
#   Thing3.Thing/
#   Thing4.Thing/
#   Thing5.Thing/
#   Thing6.Thing/
#   Thing7.Thing/
#   Thing8.Thing/
#   Thing9.Thing/
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$

The directories now show up in git as needing to be added. I edited .gitignore to add Thing*.Thing/bin thus:

Thing*.Thing/bin
*.a
*.dSYM
*.o
*.so
*~
a.out
core
posixver.h
timer.h

I reran git status:

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   .gitignore
#   modified:   makefile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   b+tree
#   b+tree.cpp
#   cswap.c
#   qs.c
#   qs2.c
#   qs3.c
#   select.c
#   shm
#   shm.c
#   sleepers-awake.c
no changes added to commit (use "git add" and/or "git commit -a")
$

So, the regexes (globs?) can be made to work. I also reran the test (after cleaning up the first one) using */bin in .gitignore; same result — the pattern worked and suppressed the directories.

Tested on Mac OS X 10.9 (Mavericks) with git --version reporting 1.8.3.4 (Apple Git-47).

Upvotes: 1

Related Questions