vue中文件夹/文件在git提交时被忽略 : gitignore 方法介绍

1,020 阅读1分钟

你的应用程序中的文件或目录的路径被列在gitignore文件中。这些文件在git推送或提交操作中不会被提交。

新的Vuejs应用原型是使用vue-cli创建的,默认情况下,它生成的gitignore文件有以下内容。

.DS_Store
node_modules/
dist/
npm-debug.log

如果你用Visual Studio Code打开你的项目,它会创建一些缓存文件。

所以你需要在gitignore文件中添加这些文件。

VScode配置

.vscode

如果你使用sublime编辑器,你必须在gitignore中添加以下文件

SublimeText 配置

*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace

对于intelli idea编辑器,.idea文件夹会被生成,所以在gitignore文件中添加这个路径

.idea .idea\_modules/

Vuejs项目在npm安装过程中会将依赖项安装到node_modules,同时构建项目会生成文件并输出到dist文件夹。

node_modules/
/dist

如果你的项目使用grunt或**bower**包管理器,只需添加以下内容即可

### package manager config
.grunt
bower_components

api secret key information are stored in environment configurations using dotenv library. 
# dotenv environment configs
.env
.env.test
.env*.local

最后添加缓存相关的文件,如下所述

.npm
# eslint cache
.eslintcache

# stylelint cache
.stylelintcache

node npm和yarn包管理器会产生调试日志文件,添加以下文件

.npm
# eslint cache
.eslintcache

# stylelint cache
.stylelintcache


和其他节点应用一样,Vuejs应用也有很多类似的东西需要添加。

下面是一个完整的vuejs应用程序的.gitignore文件。

.vscode

# package manager log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.npm
# eslint cache
.eslintcache

# stylelint cache
.stylelintcache


# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

node_modules/
/dist

总结

gitignore是添加在git提交时被忽略的文件的重要步骤。

因此,请确保你理解并根据你的应用需求添加它。