如何使用git来管理一个代码库,但有不同的环境 [英] How to use git to manage one codebase but have different environments

查看:562
本文介绍了如何使用git来管理一个代码库,但有不同的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用git作为个人项目,并且遇到了针对两种不同环境使用一个代码库的问题,并且想知道使用git的最简单方法是什么。



主桌面



我在我的大部分开发中都使用这台机器。我在这里有一个git存储库,我克隆了一个在我的内部服务器上使用的空存储库。我在这里完成了大部分工作,并将其推回到内部服务器,以便我可以将其作为真相的主人并简化备份。

笔记本电脑



我有时想在旅途中进行编码,所以我从内部服务器做了一个克隆,并创建了一个名为laptop-branch的新分支。不幸的是,某些目录MSVC ++版本与主桌面环境不同。我只是修改了笔记本电脑分支中的文件,并将它们提交到那里。



现在我在用笔记本电脑度假时做了很多更改,并且希望推送他们的起源,但不希望我所做的与目录和编译器版本相关的更改被推回原点。



最好的方法是完成这项工作?

编辑:在这种情况下,它不是一个配置文件,而是一个改变了的VC ++解决方案/项目文件。 / p>

解决方案

我这样做......



...不是通过 .gitignore



提交特定于环境的文件。在CodeIgniter中,这意味着




  • .htaccess


  • config.php
  • ul>

    就是这样。



    根据 应用程序的设置,这可能会有所不同效果。大多数情况下,我会说 config.example.php example.htaccess ,其中 承诺。然后,如果我必须设置一个环境,我将修改它们并在过程中重命名它们。因为它们被git忽略,所以你不必担心。



    如果你有很多环境特定的代码,那么你需要重新考虑你的应用程序的布局。

    I'm using git for a personal project at the moment and have run into a problem of having one codebase for two different environments and was wondering what the cleanest way to use git would be.

    Main Desktop

    I Use this machine for most of my development. I have a git repository here that I cloned off of an empty repository that I use on my internal server. I do most of my work here and push back to the internal server so I can use that as a master of truth and to ease making backups.

    Laptop

    I sometimes want to code on the road, so I did a clone from the internal server and created a new branch called "laptop-branch". Unfortunately some directories MSVC++ version are different than from the Main Desktop environment. I just modified the files in the "laptop-branch" and committed them there.

    Now I did a lot of changes while on vacation with my laptop, and want to push them to origin, but don't want the changes I made that were related to directories and compiler versions to be pushed back to origin.

    What would be the best way to get this done?

    edit: In this case it is not a config file, but a VC++ solution/project files that are changed.

    解决方案

    The way I do it...

    ...is not commit environment specific files via .gitignore.

    In CodeIgniter this means

    • .htaccess
    • database.php
    • config.php

    That's about it.

    Depending on how your application is setup this can have differing effects. Mostly I will have say config.example.php and example.htaccess which I will commit. Then if I have to setup an environment I will modify those and rename them in the process. Because they are ignored by git you don't have to worry about it.

    If you have lots of environment specific code then you need to rethink the layout of your application.

    这篇关于如何使用git来管理一个代码库,但有不同的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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