.gitignore配置问题

我现在想实现git同步的时候忽略node_modules下面除了@wang以外的文件夹,也就是说保留@wang文件夹,应该怎么样配置.gitignore文件呢

阅读 3.2k
2 个回答

其实这类问题,git文档上已经写了,只是你可能没看文档,或者忽略了。

.gitignore 官方文档

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):
$ cat .gitignore
    # exclude everything except directory foo/bar
    /*
    !/foo
    /foo/*
    !/foo/bar

知道了这个回到你的问题

node_modules/
// 排除这个文件夹。
!node_modules/@wang

但可能你已经之前就把node_modules整体忽略了,导致现在加入排除文件,没有效果。

这时再看下文档。说可以参考:

SEE ALSO
git rm 官方文档

看下来就可以发现:

// -r 在给出前导目录名时允许递归删除。
// --cached 从缓存中删除
git rm -r --cached node_modules/@wang
git status
// 查看状态

这时你就会发现 node_modules/@wang这个文件夹可以提交了。

如果觉得英文文档有障碍,可以下载翻译插件等工具,或者搜索查看中文文档。

或者也可以通过搜索(不能科学上网的情况下,推荐必应搜索),搜索git排除被忽略文件夹下的某个文件夹 等关键词。

这里有个坑,翻了下百度,这篇文章可以解决你的问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题