Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

php - use git smudge/clean to replace file contents

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

smudge

(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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...