如何在所有分支上以及在拉取之后保留对文件的本地更改,但从不提交更改 [英] How to preserve local changes to a file on all branches, and after pulls, but never commit changes

查看:44
本文介绍了如何在所有分支上以及在拉取之后保留对文件的本地更改,但从不提交更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有某些配置文件(在RoR之类的文件中:.env,config/database.yml,.ruby-version),我想在本地环境中自定义它们.

I have certain config files (in RoR stuff like: .env, config/database.yml, .ruby-version), and I want to customize them on my local environment.

我知道如何忽略文件,以便不在本地进行跟踪,但是如何在拉"或合并"之后停止文件与原点的同步?

I know how to ignore the file so they are not tracked locally, but how can I stop the file being synced with the origin after a "pull", or "merge"?

推荐答案

我建议仅对那些配置文件的 template 版本,而不是对带有其值的实际配置文件进行版本控制. 您可以考虑使用

I would recommend to version only template of those config files, instead of the actual config files with their valued.
You could consider a content filter driver (using .gitattributes declaration) in order to generate the actual files.

该想法是管理版本中的那些配置文件,但使用 template 占位符代替实际(敏感)值.
生成的文件仍被忽略(.gitignore)

The idea is to manage those config files in version, but with template placeholders in place of the actual (sensitive) values.
The generated files remains ignored (by the .gitignore)

  • 涂抹部分可以用实际值(在结帐时)替换模板内容
  • 干净的部分可以恢复模板(提交时)

(图片来自"自定义Git-Git属性",来自" Pro Git书" )

(image from "Customizing Git - Git Attributes", from "Pro Git book")

主要思想是:如果值取决于环境,则污迹脚本将根据环境实际值替换占位符值,这些值可能是从仓库外部获取的(特别是对于生产价值而言是正确的.

The main idea is: if values are depending on the environment, the smudge script would replace the placeholder values with actual values depending on the environment, values fetched possible from outside the repo (this is especially true for production values).

这篇关于如何在所有分支上以及在拉取之后保留对文件的本地更改,但从不提交更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆