我需要包括一些文件在我的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拉。然后覆盖我的所有更改。
从git 2.24.1版本开始,推荐的方法是跟踪存储库中文件的模板,将它们复制到新文件中并在本地修改它们(忽略.gitignore中的新文件名):
Users often try to use the assume-unchanged and skip-worktree bits to
tell Git to ignore changes to files that are tracked. This does not
work as expected, since Git may still check working tree files against
the index when performing certain operations. In general, Git does not
provide a way to ignore changes to tracked files, so alternate
solutions are recommended.
For example, if the file you want to change is some sort of config
file, the repository can include a sample config file that can then be
copied into the ignored name and modified. The repository can even
include a script to treat the sample file as a template, modifying and
copying it automatically.
从git 2.24.1版本开始,推荐的方法是跟踪存储库中文件的模板,将它们复制到新文件中并在本地修改它们(忽略.gitignore中的新文件名):
Users often try to use the assume-unchanged and skip-worktree bits to
tell Git to ignore changes to files that are tracked. This does not
work as expected, since Git may still check working tree files against
the index when performing certain operations. In general, Git does not
provide a way to ignore changes to tracked files, so alternate
solutions are recommended.
For example, if the file you want to change is some sort of config
file, the repository can include a sample config file that can then be
copied into the ignored name and modified. The repository can even
include a script to treat the sample file as a template, modifying and
copying it automatically.