ignoring any 'bin' directory on a git proj

2019-01-01 02:37发布

I have a directory structure like this:

.git/
.gitignore
main/
  ...
tools/
  ...
...

Inside main and tools, and any other directory, at any level, there can be a 'bin' directory, which I want to ignore (and I want to ignore everything under it too). I've tried each of these patterns in .gitignore but none of them work:

/**/bin/**/*
/./**/bin/**/*
./**/bin/**/*
**/bin/**/*
*/bin/**/*
bin/**/*
/**/bin/* #and the others with just * at the end too

Can anyone help me out? The first pattern (the one I think should be working) works just fine if I do this:

/main/**/bin/**/*

But I don't want to have an entry for every top-level directory and I don't want to have to modify .gitignore every time I add a new one.

This is on Windows using the latest msysgit.

EDIT: one more thing, there are files and directories that have the substring 'bin' in their names, I don't want those to be ignored :)

标签: git gitignore
13条回答
闭嘴吧你
2楼-- · 2019-01-01 03:14

I didn't see it mentioned here, but this appears to be case sensitive. Once I changed to /Bin the files were ignored as expected.

查看更多
余生请多指教
3楼-- · 2019-01-01 03:15

[Bb]in will solve the problem, but... Here a more extensive list of things you should ignore (sample list by GitExtension):

#ignore thumbnails created by windows
Thumbs.db
#Ignore files build by Visual Studio
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
查看更多
流年柔荑漫光年
4楼-- · 2019-01-01 03:15

Adding **/bin/ to the .gitignore file did the trick for me (Note: bin folder wasn't added to index).

查看更多
墨雨无痕
5楼-- · 2019-01-01 03:16

As a notice;

If you think about .gitignore does not work in a way (so added foo/* folder in it but git status still showing that folder content(s) as modified or something like this), then you can use this command;

git checkout -- foo/*

查看更多
一个人的天荒地老
6楼-- · 2019-01-01 03:25

for 2.13.3 and onwards,writing just bin in your .gitignore file should ignore the bin and all its subdirectories and files

bin

查看更多
倾城一夜雪
7楼-- · 2019-01-01 03:27

Before version 1.8.2, ** didn't have any special meaning in the .gitignore. As of 1.8.2 git supports ** to mean zero or more sub-directories (see release notes).

The way to ignore all directories called bin anywhere below the current level in a directory tree is with a .gitignore file with the pattern:

bin/

In the man page, there an example of ignoring a directory called foo using an analogous pattern.

Edit: If you already have any bin folders in your git index which you no longer wish to track then you need to remove them explicitly. Git won't stop tracking paths that are already being tracked just because they now match a new .gitignore pattern. Execute a folder remove (rm) from index only (--cached) recursivelly (-r). Command line example for root bin folder:

git rm -r --cached bin
查看更多
登录 后发表回答