如何告诉 GIT,它应该只处理这些和这些子文件夹?

How to tell to GIT, it should take care of only these and these sub-folders?

我想在特定的开发环境中使用git。 元交易者 4.

开发目录的结构是固定的,是这样的:

MQL4
  Expert
  Files
  imagery
  Include
  Indicators

有些目录默认带有示例文件。 我的想法是在这些目录下创建目录,并在.git忽略中指出,我希望git.

只需要考虑这些目录
MQL4
  Expert
    MyGITExperts
  Files
  imagery
  Include
    MyGITInclude
  Indicators
    MyGITIndicators

我的想法对吗? 还有更好的吗? 如何告诉 git,它应该只处理这些和这些子文件夹?

是的,有办法。

来自 git 文档 排除除特定目录 foo/bar 之外的所有内容的示例(注意 /* - 没有斜杠,通配符也会排除 foo/bar 中的所有内容):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar

http://git-scm.com/docs/gitignore

你的情况 我假设 MQL4 在您的项目根目录中(那里有 .git 文件)

/*
!/MQL4
/MQL4/*
!/MQL4/Expert/MyGITExperts
!/MQL4/Files
!/MQL4/imagery
!/MQL4/Include/MyGITInclude
!/MQL4/Indicators/MyGITIndicators

当您有大量此类文件夹时,这通常不是一个好主意

来自documentation,

gitignore - Specifies intentionally untracked files to ignore

因此,首先您需要提及您不想跟踪的文件,然后包括您想要处理的文件。

例如,让我们说您在 Include/ 中还有几个 directories/files 您需要先忽略这些,然后显式取消忽略 Include/MyGITInclude/ 目录

/Include/*
!/Include/MyGITInclude/

通过这种方式,您可以获得所有 MyGITInclude/ 目录,包括子目录及其文件。对其他 directories/sub-directories.

做同样的事情

干杯!