gitignore 作用
可以忽略对项目没有用的文件
生成.gitignore三种方式
第一种方式:
github上的gitignore项目:https://github.com/github/gitignore 编写了很多语言的共用的 gitignore 文件(比如:搜索node)
第二种方式:
在线生成 .gitignore 文件的网站:https://www.toptal.com/developers/gitignore
将所需的文件复制到项目的根目录,文件名为.gitignore
实际操作
# 初始化 git 项目$ npm init -y$ npm install moment -S# 初始化 git 仓库$ git init# 查看没有状态的文件$ git status未跟踪的文件:(使用 "git add <文件>..." 以包含要提交的内容)node_modules/package.json提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
添加 .gitignore 文件,再次进行 git status
$ git status未跟踪的文件:(使用 "git add <文件>..." 以包含要提交的内容).gitignorepackage.json提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)node_modules文件就不再显示了
如果现在要忽略的文件之前提交过,直接更改.gitignore 是不生效的,因为git已经保存了一遍快照,需要如下操作:
$ git rm --catched -r .# 删除git的缓存,但是不会删除提交日志# 然后gitignore下的内容就都生效了
第三种方式
安装 VScode 编辑器插件:.gitignore Generator
使用 Ctrl+Shift+P 唤起搜索,输入 git 进行搜索
选中之后,可以在里面选择需要配置 .gitignore 文件
不过我的电脑(windows)好像不能唤出语言环境,使用不了该插件
