简体   繁体   English

Git:忽略文件而不是目录中的子目录

[英]Git: ignore files but not sub-directories in a directory

I have a project in which all development is done at some directory depth, and so I'm used to cd-ing to a second-level directory and write some temporary files there. 我有一个项目,其中所有开发都在某个目录深度完成,所以我习惯于转到二级目录并在那里写一些临时文件。 The tree looks like this: 树看起来像这样:

repo
    .git/
    project/
        dev/
            important_stuff/
            more_stuff/
            README
        prod/
            important_stuff/
            more_stuff/
            README
        temp_1.txt
        test.cc

I would like to git-ignore exactly files that are directly in project/ - temp_1.txt and test.cc in this case. 在这种情况下,我想git-ignore直接在project / - temp_1.txttest.cc中的文件。 How can I do this? 我怎样才能做到这一点?

You can do the following: 您可以执行以下操作:

project/*
!project/*/

This will ignore all files in project but unignore all directories in project . 这会忽略所有文件中的project ,但屏蔽所有目录中project

You'll need to ignore: 你需要忽略:

project/temp_1.txt 项目/ temp_1.txt

project/test.cc 项目/ test.cc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM