2015-12-11 196 views
1

我排除了node_modules中除了某些文件以外的所有文件。所以我在git忽略文件中编写代码,如下所示。Gitignore文件无法正常工作

node_modules/angular/angular.js 
!node_modules/angularfire/dist/angularfire.js 
!node_modules/todomvc-app-css/index.css 
!node_modules/todomvc-common/base.css 
!node_modules/todomvc-common/base.js  

node_modules/ 

但它不起作用。我怎么能解决这个问题?

+0

请澄清“不行”:显示您获得的行为,并说出您的预期。我的猜测是,你必须把!遵守其他规则。 –

回答

2

正如我在 “How do I add files without dots in them (all extension-less files) to the gitignore file?” 详细的,主要是有一个规则与.gitignore要记住:

It is not possible to re-include a file if a parent directory of that file is excluded. ()
:除非某些条件,在满足混帐2.7+)

这意味着,当你排除一切时('node_modules/'),你必须白名单文件夹,才能白名单文件。

# Ignore everything under node_modules 
node_modules/* 

# Exceptions the subfolders 
!node_modules/**/ 

# Exceptions the files (since the parent folders are not ignored) 
!node_modules/angularfire/dist/angularfire.js 
!node_modules/todomvc-app-css/index.css 
!node_modules/todomvc-common/base.css 
!node_modules/todomvc-common/base.js 
2

我觉得这里的问题是,要排除的完整node_modules文件夹后,您排除了某些文件,这可能会覆盖以前的夹杂物/排除。这意味着在开始时你说你想包含和排除node_modules文件夹中的一些文件,但是稍后你只需告诉git“好,不要忘了,只是忽略整个文件夹”。因此,顺序转向可能是一个很好的开始。

但是我们可能还没有完成。另外,当你排除整个文件夹而不是文件时,如果你想排除它们,git将无法在其中找到任何文件。我们假设你忽略了文件夹node_modules,但是想在此之后排除其中的一些文件。它可能不会工作,因为没有文件夹来检查这些文件了。该文件夹实际上被忽略。

因此,您可以尝试的是忽略文件夹中的所有文件,然后对这些文件进行排除。

# ignore all files in the folder 
node_modules/**/* 

# but not those files 
!node_modules/angularfire/dist/angularfire.js 
!node_modules/todomvc-app-css/index.css 
!node_modules/todomvc-common/base.css 
!node_modules/todomvc-common/base.js 

希望这个作品。