gitignore 不忽略某些文件

1,926 阅读1分钟

常用配置

.DS_Store
node_modules
npm-debug.log
.idea
package-lock.json
.vscode
yarn-error.log

不忽略某些文件

比如我们要忽略 node_modules 下的某个文件,例如 html-loader(可能因为某些原因,需要修改此文件代码)

错误姿势

node_modules/                      ❌
!node_modules/html-loader          ✔️

正确姿势

node_modules/*                     ✔️
!node_modules/html-loader          ✔️

特别注意

新建的文件在git中会有缓存,如果某些文件已经被纳入了版本管理中,就算是在.gitignore中已经声明了忽略路径也是不起作用的,这时候我们就应该先把本地缓存删除,然后再进行git的push,这样就不会出现忽略的文件了。git清除本地缓存命令如下:

git rm -r --cached .
git add .
git commit -m 'update .gitignore'