git - 忽略来自 git commit 的文件,但保护它不被清理

标签 git gitignore

在我的工作树中,我混合了 .gitignore 中的文件:

  1. 构建输出
  2. 不应包含在存储库中的敏感文件(例如密码、本地服务器的连接详细信息)

如果我想从头开始重建我的项目,我可以执行 git clean -x 来删除 (1) 中的构建输出。但这也会删除 (2) 中的敏感文件。

有没有办法标记一个文件,使其不受 git clean 的影响,同时仍被 git commit 忽略?

最佳答案

git-clean 的文档说 -x:

-x

Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options.

所以如果你想保留,比如说,keys.pem,你会调用

git clean -fdxe keys.pem

您还可以创建 alias为命令。

关于git - 忽略来自 git commit 的文件,但保护它不被清理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43680588/

相关文章:

Git:获取分支上的最新提交

git - 从 Bitbucket 构建 Bamboo,部署到 Azure 云

git - 将 KDiff3 设置为默认 merge 工具

Git 无法忽略 Visual Studio 中的 node_modules

git - .gitignore 不忽略 .idea 路径

git - 如何忽略 git status 中的 .gitignore 文件?

git - 我可以将 GitLab 社区版用于商业项目吗?

Java 监控 GitHub 存储库

python - 使用 GitHub 的 Azure Function CI/CD 部署丢失了 .gitignore 中的重要文件

git - 将多个 gitignore 文件包含在一个文件中