git - 将文件保存在 Git 存储库中,但不跟踪更改

标签 git

我需要在我的 GitHub 存储库中包含一些文件,但不跟踪它们的更改。我怎样才能做到这一点?一个示例用例是包含敏感用户信息(例如登录凭据)的文件。

例如,我将此框架的新安装部署到新客户端,我想下载以下文件(它们具有默认值 CHANGEME),我只需要针对此客户端进行特定更改(数据库凭据、电子邮件地址信息、自定义 CSS)。

// The production config files. I want the files but they need to be updated to specific client needs
application/config/production/config.php
application/config/production/database.php
application/config/production/tank_auth.php
// Index page, defines the environment (production|development)
/index.php
// All of the css/js cache (keep the folder but not the contents)
/assets/cache/*
// Production user based styling (color, fonts etc) needs to be updated specific to client needs
/assets/frontend/css/user/frontend-user.css

当前如果我运行

git clone git@github.com:user123/myRepo.git httpdocs

然后编辑上面的文件,一切都很好。直到我发布修补程序或补丁并运行 git pull。然后我的所有更改都会被覆盖。

最佳答案

git 有不同的解决方案来做到这一点。首先更改您不想被跟踪的文件并使用以下命令:

git update-index --assume-unchanged FILE_NAME

如果您想再次跟踪更改,请使用此命令:

git update-index --no-assume-unchanged FILE_NAME

git-update-index documentation

关于git - 将文件保存在 Git 存储库中,但不跟踪更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9794931/

相关文章:

git - 特定于平台的 git 配置文件

python - 从 bitbucket repo 的分支安装 pip

bash - 回答多个命令行提示到 GitHub 用户名/密码

windows - 如何让 GIT 将目录连接视为 Windows 上的常规文件夹?

git - 是否可以在 gitlab-ci 中将另一个分支构建到另一个目录?

git - git中的存储库和分支有什么区别?

git - 无法从管道作业克隆 Azure DevOps 存储库

windows - 我可以通过 cmd.exe 在 Windows 上为 git 设置自动完成吗?

Git clean 不删除文件

git - 未执行Azure功能的自动部署