git提交初始提交配置,但永远不会再次? [英] git commit config on initial commit but never again?

查看:112
本文介绍了git提交初始提交配置,但永远不会再次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始为我的项目使用git,当我创建一个项目时,它有一个包含配置文件的配置文件夹:

  application / config / config.php 
application / config / database.php
application / config / routes.php

当我第一次提交时,我希望提交这些文件(使用它们的默认值),因此它们作为默认配置存在于存储库中,如果我克隆到存储库,则会获取这些文件。当我更新它们以包含我的配置变量(对于我正在开发的版本)时,我不希望它们在存储库中更新,我希望它们保持其在存储库中的默认状态。



我试着先将它们提交到它们的默认状态,然后将它们添加到我的.gitignore文件中,如下所示:

  application / config / * 

现在当我提交配置文件aren' t提交(yay!)但是原始默认值消失,文件夹application / config /不再存在于我的仓库中。



我假设我在这里丢失了一些明显的东西,但我对git没有经验。



如何在我的第一次提交时提交配置文件,但是不会再一次 将它们保留在存储库中的默认状态下?

解决方案

您可以在版本化后更新其索引:

  git update-index --assume-unchanged application / config / config.php 

或者你甚至可以更多地更新索引:

  git update-index --skip-worktree application / config /config.php 

(如),并根据当前环境生成最终的配置文件。

I have started to use git for my projects, when I create a project it has a config folder containing configuration files:

application/config/config.php
application/config/database.php
application/config/routes.php

When I first commit I want these files (with their defaults) to be committed, so they exist in the repository as the "default" configurations and if I clone to repository I get these files. When I update them to contain my configuration variables (for the version I'm developing on) I don't want them to be updated in the repository, I want them to remain in their default state in the repository.

I have tried first committing them in their default state and then adding them to my .gitignore file, like so:

application/config/*

Now when I commit my configuration files aren't committed (yay!) however the original defaults disappear, the folder application/config/ no longer exists in my repository.

I assume I'm missing something obvious here, but I'm very inexperienced with git.

How can I commit the configuration files on my first commit but never again with them remaining in the repository in their default state?

解决方案

You could, once versioned, update their index:

 git update-index --assume-unchanged application/config/config.php

Or you could even update the index more permently:

 git update-index --skip-worktree application/config/config.php

(as show in "git update-index --assume-unchanged and git reset")


The other solution is to not version those final config file (since their content may vary as you pointed out), but to use a filter driver:

You would versioned:

  • template files (application/config/config.tpl)
  • config value files (one default, and other for your different environments)
  • a script able to recognize the content of a config file (since it won't have its path) and generate the final config files according to the current environment.

这篇关于git提交初始提交配置,但永远不会再次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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