如何在本地工作目录,远程工作目录和git ftp目标中拥有不同版本的文件? [英] How can I have different versions of a file in the local working directory, remote working directory and git ftp target?

查看:330
本文介绍了如何在本地工作目录,远程工作目录和git ftp目标中拥有不同版本的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Git来管理CodeIgniter项目。我在本地机器上工作并推送到远程服务器,在那里测试所有内容。然后我使用 git ftp push 更新另一台主机上的生产站点。



现在,需要三个不同的index.php文件,每个环境一个,我只是设置了一个不同的环境变量。

因此我需要gitignore index.php文件,甚至是git-ftp-忽略它。对于它正在工作的ftp。对于普通的gitignore来说,它并不是:它不断更新远程服务器上的index.php文件。



我试着做 git rm - 缓存的index.php ,但我得到的是它完全删除了远程服务器上的index.php文件。



我在做什么错误?

编辑:看起来这不是我能用git做的事情,但我发现了一个更好的方法来设置CodeIgniter环境变量

解决方案

首先,忽略机制对已在存储库中进行跟踪的文件没有任何影响。因此,如果您希望 .gitignore 工作,您必须从存储库中删除该文件(与您一样,使用 git rm --cached ),但正如你所看到的那样,当你更新远程仓库时它会被删除。



总之,我不认为你应该在这种情况下 .gitignore 文件。 git中被忽略的文件的语义有一个微妙的问题,它让我感到很多次 - 忽略文件被认为是一次性的,因为该机制是为构建产品而设计的。你在这里有一个你想被忽略的文件,但是很珍贵,而git目前没有指定的方式。



例如,在你的情况下,如果你手动重新创建 index.php ,那么这看起来一切正常,但如果你使用 git checkout old-commit 返回到旧版本,其中 index.php 被跟踪,然后返回到原来的位置,使用 git checkout - ,你的 index.php 将被删除!



你可以改变你的 index.php 来从其他文件中找到环境变量的正确设置:


  1. 存储库外

  2. 或存储在存储库中,忽略,并且存储库中从未跟踪过的路径

理想情况下,还要为其他文件不存在时添加默认值。


I'm using Git to manage a CodeIgniter project. I work on my local machine and push to a remote server, where I test everything. Then I use git ftp push to update the production site on another host.

Now, to make this work I need three different index.php files, one for every environment, where I just set a different environment variable.

So I need to gitignore the index.php file, and even git-ftp-ignore it. For the ftp it is working. For the normal gitignore it isn't: It keeps updating the index.php file on the remote server.

I tried doing git rm --cached index.php, but what I get is that it completely deletes the index.php file on the remote server.

What am I doing wrong?

Edit: It seems it's not something I can do with git, but I've found a better way to set the CodeIgniter environment variable.

解决方案

Firstly, the ignore mechanism doesn't have any effect on files that are already being tracked in the repository. So, if you want the .gitignore to work, you have to remove the file from the repository (as you did, with git rm --cached) but then, as you observed, it'll be deleted when you update the remote repository.

In summary, I don't think you should .gitignore the file in this situation. There's a subtlety about the semantics of ignored files in git which has caught me out number of times - ignored files are regarded as disposable, since the mechanism is designed for build products. What you have here is a file that is you want to be ignored, but is precious, and git currently doesn't have a way of specifying that.

For example, in your situation, if you recreate index.php manually, that will appear to all work fine, but then if you use git checkout old-commit to move back to an old version where index.php was tracked, and then go back to where you were before, with git checkout -, your index.php will be deleted!

I would suggest that you change your index.php to source the right setting for the environment variable from some other file which is either:

  1. outside the repository
  2. or is in the repository, ignored, and at a path that has never been tracked in the repository

Ideally, then also add a default value for when that other file doesn't exist.

这篇关于如何在本地工作目录,远程工作目录和git ftp目标中拥有不同版本的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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