23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

見せたくないファイル・各開発者の環境毎に設定内容が変わるようなファイルをGitでどう管理するか

Posted at

考察

見せたくないファイル

「GitHubやBitbucketを利用してチーム開発したいけど、
本番環境に適用する設定ファイル等はほかのメンバーに見せたくない」
これって、 git ではそこそこややこしい問題だと思う。
今後、ファイル単位でのアクセス制御が出来るようになってくれるようなこともあるかもしれないが、
現状ではそれが望めないので ignore するかってことになるかと思うのだが、
.gitignore に対象ファイルの path を記述することすらしたくない。
もう少しスマートにやる為には、 exclude を使うといいんじゃないか。

開発者の環境毎に設定内容が変わってしまうファイル

開発者の環境によって設定内容が変わってしまうようなファイルがいくつか存在する。
そういったファイルは、とりあえず

example.php
switch (gethostname())
{
	case 'www.production.ne.jp':// 本番環境
		define('FUEL_PATH', '/www/lib/FuelPHP/');
		define('LOG_DIR', realpath(__DIR__.'/../app/').DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR);
	break;

	default :// ローカル環境
		error_reporting(-1);
		ini_set('display_errors', 1);

		/* >>>> 各自の環境に合わせて書き換える */
		define('FUEL_PATH', 'Write the directory that contains the FuelPHP.');
		define('LOG_DIR', 'Write the directory that contains the log.');
		/* <<<< 各自の環境に合わせて書き換える */
	break;
}

みたいな感じにしてcommitしておいて、開発者各自が適宜自分の環境に合わせて設定内容を記述し、skip-worktreeするみたいな感じかなと。

実践

exclude

.git ディレクトリ配下に info というディレクトリがあって、
その中に exclude ファイルが格納されている。(~/.git/info/exclude)
ここに管理対象から外したいディレクトリやファイルの path を記述しておけば
.gitignore ファイルに記述する必要がなく、
対象となるディレクトリやファイルの path が公開されることがないので安心。
記法は .gitignore と同じ。

skip-worktree

考察に掲載したようなファイルがあると仮定して、
そのファイルの path が「root/public/index.php」とかだったりするとする。
で、ファイルの記述を自分の環境に合わせて変更したりすると
git-statusに出てきてしまうことになるわけだが、

git update-index --skip-worktree root/public/index.php

↑を実行するとgit-statusに表示されなくなるので、commitmergeしても反映されなくなる。

23
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?