.gitignore忽略所有文件,然后递归地允许* .foo [英] .gitignore ignore all files then recursively allow *.foo
问题描述
我想忽略我的资源库下面的文件夹中的所有内容,除了带*号的文件外, .foo
(如果有人想知道这样做是否合理 - 我实际上是为我所有的Logic项目制作一个git存储库 - mac上的音乐软件 - 但我只想存储实际的项目文件* .logic)
我要说出来,所以我们都在同一个盘子里。
这就是我从零开始做的事:
设置:
mkdir temp
cd temp
mkdir testdir
cd testdir
touch include.foo
touch dontinclude.bad
cd ..
git init
touch .gitignore
粘贴这是为了.gitignore
#忽略所有
/ *
#但不是这些文件...
!.gitignore
!*。foo
git status
如果我输入'git add',唯一未跟踪的文件是.gitignore
- 没有改变,只有.gitignore被看到,我的2个文件被忽略。
为什么不能这样工作,以及如何改变上面的过程以使其工作?
以下是我从中得到.gitignore文件的极其类似的问题。
我使用git --version 1.7.7(也试过1.7.3) - .gitignore忽略所有文件,然后递归地允许某种类型的文件
你的问题是,开始时 / *
模式匹配顶层的所有文件和目录 - 包括 testdir
,所以 testdir
中的所有内容都会被忽略。
这就是你想要:
#忽略所有
*
#不要忽略目录,所以我们可以递归到他们
!* /
#不要忽略.gitignore和* .foo文件
!.gitignore
!*。foo
使用此配置执行 git add。
时,您应该发现只有 .gitignore
和 *。foo
文件列为要提交的更改。
There's already several questions similar to this, but none of the answers work for me.
I want to ignore everything in the folders below my repository except files with *.foo
(If anyone is wondering how this can be justified - I'm actually making a git repository for all my "Logic" projects - music software on the mac - but I only want to store the actual project files *.logic)
I'm going to spell it out, so we're all on the same plate. Here's what I do, starting from scratch:
Setup:
mkdir temp
cd temp
mkdir testdir
cd testdir
touch include.foo
touch dontinclude.bad
cd..
git init
touch .gitignore
Paste this in to .gitignore
# Ignore all
/*
# But not these files...
!.gitignore
!*.foo
git status
And the only untracked file is .gitignore
if I typed 'git add .' - no change, only .gitignore is seen and my 2 files are ignored.
Why doesn't this work and how can you change the procedure above to make it work?
Here's the extremely similar question where I got the .gitignore file from. I'm using git --version 1.7.7 (also tried 1.7.3) - .gitignore to ignore all files, then recursively allows files of a certain type
Your problem is that the /*
pattern at the beginning is matching all files and directories at the top level - including testdir
, so everything inside testdir
is ignored.
This is what you want:
# Ignore everything
*
# Don't ignore directories, so we can recurse into them
!*/
# Don't ignore .gitignore and *.foo files
!.gitignore
!*.foo
When you do a git add .
with this config, you should find you have only .gitignore
and *.foo
files listed as changes to be committed.
这篇关于.gitignore忽略所有文件,然后递归地允许* .foo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!