Git - Ignore certain files contained in specific folders
Asked Answered
E

6

21

I'm using msysgit and have a project tree that contains many bin/ folders in the tree. Using the .gitignore file in the root of the project I need to ignore all .dll files that reside within a bin/ folder anywhere in the project tree. I've tried "bin/*.dll" but that doesn't work, I assume it is only working against the bin/ folder in the root of the project.

Episcopalian answered 9/6, 2009 at 17:35 Comment(4)
I do confirm "git add --dry-run *.dll" only add non-ignored .dll. Could you post the content of your .gitignore file?Heyde
You are right: '*/bin/.dll' only works for 'x/bin/z.dll' (depth 2), not 'x/y/bin/z.dll' (depth 3). Looking into it now.Heyde
I am not sure gitignore pattern support recursive detection of directories... I have amended my answer.Heyde
This question ( #992301 ) seems to have a solution, but I have not been able to make it work for all depths for a given directory to ignore...Heyde
H
15

Update August 2016 (seven years later, Git 2.9.3/ Git 2.10)

**/bin/*.dll

That does work for any depth.


Original answer (2009, Git 1.6)

Did you try:

**/bin/*.dll

It does work with my msysgit1.6.3 (with a .gitignore file at the root directory of the Git workspace).

Actually the above would only ignore 'x/bin/z.dll', not 'x/y/bin/z.dll'.

Another syntax could be:

**/*/bin/*.dll

But that would only get depth 3, not depth 2!

So if you do not have too many place where *.dll need to be ignored, the simplest solution would still be a local .gitignore file in those 'bin' directories...

Or a collection of directive to cover the main first depths:

bin/*.dll
**/bin/*.dll
**/*/bin/*.dll
**/**/*/bin/*.dll

and so on, all in one .gitignore file.

Heyde answered 9/6, 2009 at 17:47 Comment(1)
I'm using msysgit 1.6.3 also but the pattern */bin/.dll didn't work. I added that pattern to my .gitignore in the root and then tried "git add --dry-run *.dll" from the root and it listed my .dll files contained in the bin/ folders of my project tree.Episcopalian
C
15

Just had a similar problem and realized: The files were already added and checked in to git.

How to recognize the difference: Git didn't show the files as "new", but as "modified". This details has cost me quite some time...

If that is the problem, simply "git rm" these files and start over. Suddenly, .gitignore starts to work as expected.

Cabstand answered 5/9, 2010 at 13:22 Comment(2)
this worked for me, but is the dumbest thing I've had to do involving Git.Pantywaist
git rm -f -r /path #to force and remove a folder.Fiscal
M
13

I just have /bin in my file and it seems to work. It ignore the whole folder (as opposed to specific files in it)

Here are the complete contents as of now (still evolving).

.svn*
obj/
bin/
*.suo
*.user
Log/
log/
*.db
Mecklenburg answered 11/6, 2009 at 23:25 Comment(0)
J
4

.gitignore on windows, just does not seem to work. I am using msysgit v 1.7.6 beta, and it just does not work the way it should per the .gitignor man page. Now, if I copy the contents of my .gitignore file to the $GIT_DIR/info/exclude file, inside the repo, things do work.

So, the bummer is that this does not get replicated, but it is better than nothing.

Joule answered 2/9, 2011 at 19:6 Comment(0)
C
1

Depending on language you are using, you can choose it from link

For example, If you are using java, you can use gitignore

Also https://www.gitignore.io/ allows you to create gitingore file online, you just need to enter operating system, IDE or programming language and based on it, It will give you gitignore file. Using it you can create gitignore file for your project easily.

Countermarch answered 20/7, 2018 at 7:0 Comment(0)
E
0

*/bin worked for me

I'd think that */bin/ would as well.

Erumpent answered 2/4, 2010 at 2:29 Comment(2)
That only works to depth 1: kernel.org/pub/software/scm/git/docs/gitignore.html "wildcards in the pattern will not match a / in the pathname"Heelpiece
so what would work? */bin*? I think I did that later... for a different directory.Erumpent

© 2022 - 2024 — McMap. All rights reserved.