自己搭建个人网站的注意事项,上海网站建设网页制作培训,美食网站建设策划书,哪些网站是vue做的如果想让 Git 忽略指定目录#xff0c;不进行更新或提交#xff0c;可以使用 .gitignore 文件进行配置。 #x1f6e0; 方法#xff1a;使用 .gitignore 忽略目录
1️⃣ 在仓库根目录创建 .gitignore 文件
如果你的项目目录下还没有 .gitignore 文件#xff0c;可以新建…如果想让 Git 忽略指定目录不进行更新或提交可以使用 .gitignore 文件进行配置。 方法使用 .gitignore 忽略目录
1️⃣ 在仓库根目录创建 .gitignore 文件
如果你的项目目录下还没有 .gitignore 文件可以新建一个
touch .gitignore或者在 VS Code 中手动创建 .gitignore 文件。
2️⃣ 在 .gitignore 文件中添加要忽略的目录
例如想要忽略 logs/ 和 temp/ 目录
logs/
temp/⚠️ 注意
斜杠 / 代表目录例如 logs/ 表示忽略 logs 目录及其所有文件。如果是单个文件例如 config.json则写config.json3️⃣ 提交 .gitignore
让 Git 识别忽略规则
git add .gitignore
git commit -m Update .gitignore to exclude logs and temp directories4️⃣ 如果目录已经被跟踪需先清除缓存
如果 logs/ 或 temp/ 目录之前已经被 Git 跟踪即使你添加了 .gitignore它们仍然会被 Git 识别。此时需要执行
git rm -r --cached logs/ temp/
git commit -m Remove logs and temp from tracking
git push origin main # 推送到远程其他 .gitignore 示例
忽略所有 .log 文件
*.log忽略 node_modules前端项目
node_modules/忽略 build 和 dist 目录编译产物
build/
dist/忽略 .env 配置文件
.env结论
创建 .gitignore 并添加需要忽略的目录/文件。如果已经被 Git 跟踪执行 git rm -r --cached 清除缓存。提交 .gitignore 并推送到远程仓库。