使用git smudge / clean来替换文件内容 [英] use git smudge/clean to replace file contents
问题描述
我正尝试使用git来管理部署到我的实时网站。
我遇到的问题是我有一些设置文件,当我推到产品时我不想更新
什么我正在看的是使用hook或smudge / clean来更改文件内容,例如从
<? php
define('DB_NAME','live');
define('DB_HOST','127.0.0.1');
define('DB_USER','live_user');
define('DB_PASS','livePass');
至
<?php
define('DB_NAME','local');
define('DB_HOST','127.0.0.1');
define('DB_USER','local_user');
define('DB_PASS','localPass');
有没有人可以通过此过程与我说话
我确实想知道使用post-receive hook和shell脚本来替换内容,但理想情况下我希望在执行git checkout之前更改repo中的内容-f
未在在
之后进行活动拷贝理想情况下,我希望在执行git之前更改回购中的内容checkout -f在
之后没有在活动拷贝中更改
$ b $ p
$ b最接近的是一个过滤器内容驱动程序,它将替换 / em>
git checkout
。
(from Scott Schacon 的 Pro Git book 页面 Git Attributes :关键字扩展部分)
所以在你的情况下:一个涂抹过滤器, code> .gitattributes 文件。
请参阅 git可以在空格和制表符之间自动切换?,除非你用sed来替换本地生活这个例子)
I am attempting to use git to manage deployment to my live website. The problem that I'm having is that I have a couple of settings files that I don't want to be updated when I push to production
what I'm looking at doing is either using a hook or smudge/clean to change the file contents for example from
<?php define('DB_NAME', 'live'); define('DB_HOST', '127.0.0.1'); define('DB_USER', 'live_user'); define('DB_PASS', 'livePass');
to
<?php define('DB_NAME', 'local'); define('DB_HOST', '127.0.0.1'); define('DB_USER', 'local_user'); define('DB_PASS', 'localPass');
Is there anyone who could talk me through the process please
I did wonder about using post-receive hook and a shell script to replace the contents, but ideally I want the contents in the repo to be changed before I run git checkout -f not changed in the live copy after
解决方案ideally i want the contents in the repo to be changed before i run git checkout -f not changed in the live copy after
The closest is a filter content driver which will replace the value at the
git checkout
.(from Scott Schacon's Pro Git book page on Git Attributes: section "Keyword Expansion")
So in your case: a smudge filter, declared in a
.gitattributes
file.See "Can git automatically switch between spaces and tabs?", except you would use a sed to replace local to live (as in this example)
这篇关于使用git smudge / clean来替换文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!