[Git] 简易 .gitignore 文件

以以下目录结构为例:

image

gitignore 文件

只保留 include src 里的 .h 和 .cpp 文件,可以直接使用

# ==============================================
# 核心规则:默认忽略所有二级目录,只保留 src/  internal/ 和 include/
# ==============================================
*/*

!src/*
!internal/*
!include/*

# ==============================================
# 编译产物 / 库文件 / 目标文件
# ==============================================
*.so
*.so.*
*.o
*.a

# ==============================================
# 办公文档 / 图片(不提交到 Git)
# ==============================================
*.xls
*.xlsx
*.doc
*.docx
*.jpg
*.jpeg
*.png

# ==============================================
# Linux 安装包
# ==============================================
*.deb
*.rpm

gitattributes 文件

# 让 Git 自动识别文本文件并统一规范化
* text=auto

# 明确指定源代码文件使用 LF(即使在 Windows 上检出也保持 LF,避免脚本报错)
*.c   text eol=lf
*.h   text eol=lf
*.cpp text eol=lf
*.hpp text eol=lf

# 如果有 Windows 专属脚本,可以指定 CRLF
*.bat text eol=crlf
*.cmd text eol=crlf
posted on 2026-03-20 11:18  风惊庭前叶  阅读(25)  评论(0)    收藏  举报