git
› Pro Git
› Atlassian Git Tutorial
› Pro Git 简体中文翻译
› GitX
gracece
V2EX  ›  git

github中,一些涉及到用户配置的文件怎么处理(比如数据库用户名/密码)?

  •  
  •   gracece · Jun 30, 2013 · 11798 views
    This topic created in 4882 days ago, the information mentioned may be changed or developed.
    想把代码放在github上,不知道怎么处理好,怕一不小心把密码都push上去了。
    22 replies  •  1970-01-01 08:00:00 +08:00
    fangzhzh
    fangzhzh
    Jun 30, 2013
    1
    ignore吧, 保存在本地好了.
    或者上去前, 加密下
    gracece
    gracece
    OP
    Jun 30, 2013
    2
    @fangzhzh 比如我有一个 config.php ,在第一次push的时候放个空密码。然后设置为ignore掉之后再把密码写进去这样吗?
    Livid
    Livid
    MOD
    PRO
    Jun 30, 2013❤️9
    3
    源代码库里放 config.example.php,然后 .gitignore 里忽略 config.php。
    fangzhzh
    fangzhzh
    Jun 30, 2013❤️1
    4
    @Livid 这个正解
    yuelang85
    yuelang85
    Jun 30, 2013
    5
    @Livid 正解啊,正为这个发愁呢
    gracece
    gracece
    OP
    Jun 30, 2013
    6
    @Livid 感谢!
    gracece
    gracece
    OP
    Jun 30, 2013
    7
    突然想到为什么wordpress的代码里面只给了 wp-config-sample.php 没有 wp-config.php ,大概也是这样的原因吧。
    Livid
    Livid
    MOD
    PRO
    Jun 30, 2013
    8
    @gracece 对,很多 PHP 开源项目都是这样做的,phpMyAdmin 也是。
    lex
    lex
    Jun 30, 2013
    9
    build 的时候从 keychain 取。
    xzl380
    xzl380
    Jun 30, 2013
    10
    用我们学校的邮箱可以申请到micro 的套餐,好像5个私有。
    另外gitcafe目前免费。
    thai9quohs6jae1C
    thai9quohs6jae1C
    Jun 30, 2013
    11
    phing 用这个
    Kjuly
    Kjuly
    Jun 30, 2013❤️4
    12
    gitignore一般来说是ignore一些untracked文件(比如生成的二进制、临时文件等)
    但如果项目中已经存在了一个已经设置了参数但各参数为空的config文件 那么最好的办法还是使用

    git update-index --assume-unchanged config

    这样每个本地库对config的修改都不会被track 但服务器端的config文件还在

    而且现在越来越多的项目使用Live Build,这就避免了缺失config中的参数带来的Build Failed错误

    ---
    另外 当你需要为config文件添加新参数的时候 使用

    git update-index --no-assume-unchanged config

    来重新track文件的修改 提交修改后记得再--assume-unchanged回来 具体使用方法自己可以搜索下 建立一个测试项目试试效果 ;)
    bcxx
    bcxx
    Jun 30, 2013
    13
    @Kjuly 但是如果协作的话就要大家都设置一遍了,有其他方法可以解决这个开销么?
    timonwong
    timonwong
    Jun 30, 2013❤️1
    14
    @bcxx
    可以用 git attributes 的 filter,不过稍显复杂,每个working directory仍然需要单独设置。

    你可以考虑这种办法:
    1. 首先还是在 ${git_working_dir}/.gitignore 中排除掉 xxx.conf
    2. 使用任意安全的同步方法,维护一个专供config的库
    3. 软连接 ln -s ${path_to_real_config_folder}/xxx.conf ${git_working_dir}/xxx.conf
    est
    est
    Jun 30, 2013❤️3
    15
    测试和正式服一般是通过环境变量注入来提供db密码之类的。
    binux
    binux
    Jun 30, 2013
    16
    我的做法是在config.py中try一个import local_config.py,local_config.py不提交
    bcxx
    bcxx
    Jun 30, 2013
    17
    @timonwong 这个方法就是我现在用的啦 :)
    reorx
    reorx
    Jun 30, 2013
    18
    @binux +1
    tangzx
    tangzx
    Jul 1, 2013❤️1
    19
    越来越多的实践采用环境变量,而非本地文件
    tangzx
    tangzx
    Jul 1, 2013
    20
    默认值采用mongodb://localhost/devdb (数据库)这样的本地开发值,这样如果再配合mongo这样无schema的货货。就几乎可以0配置启动开发了,这样对对代码有兴趣的开发者很友好。如果一个项目启动配置都要很麻烦,自然让其他人不想参与其中
    ushuz
    ushuz
    Jul 1, 2013❤️2
    21
    @fangpeishi 即使私有库也不能该把密码push进去。
    这里有一篇亡羊补牢的指南,如果不小心把敏感数据push进去了如何清理。
    https://help.github.com/articles/remove-sensitive-data
    duhastmich
    duhastmich
    Jul 1, 2013
    22
    还有个类似config.example.php 的思路不过可以生成 config.php https://github.com/zweifisch/redact; 环境变量也可以只导出一个变量,APP_ENV=production,然后根据这个变量来加载不同的配置文件
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1208 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 67ms · UTC 17:30 · PVG 01:30 · LAX 09:30 · JFK 12:30
    ♥ Do have faith in what you're doing.