当前位置: 首页 > news >正文

idea开发工具中git如何忽略编译文件build、gradle的文件?

idea开发工具中: git显示下面这个文件有变更: ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/hyh-apis-springboot/build/resources/main/mapping/AccountRealnameMapper.xml 我git的根路径是: ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/ 下面是我一个项目的路径: ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/hyh-apis-springboot 我想每次编译,都让git忽略掉: ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/hyh-apis-springboot/build/ 该如何处理?

目录

✅ 解决方案:

📍完整步骤如下:

⚠️ 注意事项:

✅ 最终效果:


你可以通过 .gitignore 文件 来让 Git 忽略掉 build/ 目录下的所有内容,避免每次编译后出现变更提示。


✅ 解决方案:

你只需要在 Git 根目录的 .gitignore 文件中添加一行:

 

hyh-apis-springboot/build/


📍完整步骤如下:

  1. 打开 Git 根目录:

    cd ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/

  2. 编辑 .gitignore 文件(如果没有就创建一个):

    nano .gitignore

  3. 添加这行(确保是相对路径):

    hyh-apis-springboot/build/

  4. 保存并退出。


⚠️ 注意事项:

  1. 必须确保该文件或目录尚未被 Git 跟踪(tracked),否则 .gitignore 不生效。

    检查是否已被跟踪:

    git ls-files --stage | grep hyh-apis-springboot/build/

    如果被跟踪了,请运行以下命令将它从索引中移除(注意不会删除本地文件):

    git rm -r --cached hyh-apis-springboot/build/

  2. 然后再提交 .gitignore 的更新:

    git add .gitignore git commit -m "忽略 build/ 目录"


✅ 最终效果:

编译生成的路径:

hyh-apis-springboot/build/resources/main/mapping/AccountRealnameMapper.xml

将不会再出现在 git status 中,Git 会完全忽略整个 build/ 目录的变更。


如果你有多个模块都想忽略它们的 build/ 目录,可以更通用地写:

**/build/

这会忽略项目下所有子目录中的 build/ 文件夹。

忽略.gradle ,hyh-apis-springboot/.gradle/ 这样写不好使?

你提到写了:

 

.gradle hyh-apis-springboot/.gradle/

但 Git 仍然没有忽略掉 .gradle/ 目录,这通常有两种常见原因:


✅ 解决方法一:确保 .gradle 目录未被 Git 跟踪

.gitignore 只能**忽略未被跟踪(untracked)**的文件或目录。

🔍 步骤 1:查看是否已被跟踪

 

git ls-files --stage | grep .gradle

如果输出有 .gradle 或其中的子文件,说明已经被 Git 跟踪了。


🧹 步骤 2:从 Git 索引中移除 .gradle(不会删除本地文件)

git rm -r --cached hyh-apis-springboot/.gradle/ git rm -r --cached .gradle/


📝 步骤 3:修改 .gitignore

在 Git 根目录下(即 ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/),编辑 .gitignore 文件,添加:

gitignore

.gradle/ hyh-apis-springboot/.gradle/

或者更推荐用通配方式(更通用):

gitignore

**/.gradle/


✅ 步骤 4:提交变更

git add .gitignore git commit -m "忽略 .gradle 目录"


🧪 测试是否成功

再执行:

git status

你应该不会再看到 .gradle/ 下的文件被列出。


🔁 小结:完整操作命令

# 进入 Git 根目录 cd ~/Documents/wwwroot-dev/wlxl-backend/java/hyh-apis/ # 编辑 .gitignore(如果没有就创建) echo '**/.gradle/' >> .gitignore # 移除已跟踪的 .gradle 目录 git rm -r --cached hyh-apis-springboot/.gradle/ git rm -r --cached .gradle/ # 提交更改 git add .gitignore git commit -m "忽略所有 .gradle 目录"

http://www.dtcms.com/a/318999.html

相关文章:

  • C5.1:共发射极组态
  • 【Day 18】Linux-DNS解析
  • 如何理解“信号集是位掩码,每个bit代表一个信号”这句话?
  • 怎么在本地引入字体
  • 构建在 OpenTelemetry eBPF 基础之上:详解 Grafana Beyla 2.5 新特性
  • 防火墙环境下的全网服务器数据自动化备份平台搭建:基于 rsync 的完整实施指南
  • CentOS 7 下通过 Anaconda3 运行llm大模型、deepseek大模型的完整指南
  • Express框架
  • 【JavaEE】(9) JVM
  • ElementUI之表格
  • 企业家 IP 发展态势剖析|创客匠人
  • 计算机网络1-5:计算机网络的性能指标
  • 【python 数据加密AES-GCM + 时间戳签名方案(带时间校验)】
  • vue3 el-select 加载触发
  • tcpdump问题记录
  • 软件运行时 ffmpeg.dll 丢失怎么办?从原因排查到完美修复的完整方案
  • 【Kafka系列】第二篇| Kafka 的核心概念、架构设计、底层原理
  • 什么是 TcpCommunicationSpi
  • HTML已死,HTML万岁——重新思考DOM的底层设计理念
  • 【音视频】WebRTC C++ native 编译
  • SpringAI动态调整大模型平台
  • 数据结构----栈和队列认识
  • Spring IoC 容器核心流程(面试必懂)
  • SpringMvc的原理深度剖析及源码解读
  • crew AI笔记[1] - 简介
  • list类
  • Spring中用到了哪些设计模式
  • 容器之王--Docker镜像的管理及镜像仓库的构建演练
  • W25Q64模块
  • 智慧园区系统:打造未来城市生活新体验