git 添加除了包含特定字符串的文件

要使用 git add 添加所有文件但排除文件名中包含 "store" 字符串的文件,可以使用以下命令:

bash 复制代码
# 添加所有文件,但排除文件名包含"store"的文件
git add $(git ls-files | grep -v "store")

如果需要包括未跟踪的文件,可以使用:

bash 复制代码
# 添加所有文件(包括未跟踪的),但排除文件名包含"store"的文件
git add $(git ls-files --others --exclude-standard | grep -v "store")

命令解释:

  • git ls-files 列出所有被 Git 跟踪的文件
  • git ls-files --others --exclude-standard 列出所有未跟踪的文件(排除 .gitignore 中指定的文件)
  • grep -v "store" 过滤掉包含 "store" 字符串的文件名
  • git add $(...) 将过滤后的文件列表传递给 git add 命令

如果需要永久排除这些文件,可以将模式添加到 .gitignore 文件中:

bash 复制代码
echo "*store*" >> .gitignore
相关推荐
Bigger1 天前
为什么你的 Git 提交需要签名?—— Git Commit Signing 完全指南
git·开源·github
DianSan_ERP2 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
红豆子不相思2 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享2 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
梅孔立2 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
hnjzsyjyj2 天前
洛谷 AT_abc269_b [ABC269B]:Rectangle Detection
字符串
qq_426003962 天前
git切换当前分支到远程分支
git
ON10N3 天前
100% 纯 Vibe Coding,我是怎么用 AI 撸出一个 VS Code 插件的
git·ai编程·visual studio code
Lunar*3 天前
告别臃肿!使用 git-filter-repo 优雅清理 Git 历史记录
git