[英]How can I have different versions of a file in the local working directory, remote working directory and git ftp target?
I'm using Git to manage a CodeIgniter project. 我正在使用Git管理CodeIgniter项目。 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. 然后,我使用
git ftp push
来更新另一台主机上的生产站点。
Now, to make this work I need three different index.php files, one for every environment, where I just set a different environment variable. 现在,要进行此工作,我需要三个不同的index.php文件,每个文件用于一个环境,在这里我只是设置了一个不同的环境变量。
So I need to gitignore the index.php file, and even git-ftp-ignore it. 所以我需要gitignore index.php文件,甚至git-ftp-ignore。 For the ftp it is working.
对于ftp,它正在工作。 For the normal gitignore it isn't: It keeps updating the index.php file on the remote server.
对于普通的gitignore不是:它会不断更新远程服务器上的index.php文件。
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. 我尝试做
git rm --cached index.php
,但是得到的是它完全删除了远程服务器上的index.php文件。
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 . 编辑:看来这不是我可以用git做的,但是我找到了一种更好的方法来设置CodeIgniter环境变量 。
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. 因此,如果您希望
.gitignore
正常工作,则必须从存储库中删除文件(就像使用git rm --cached
),但是正如您观察到的那样,当更新远程存储库时,它将被删除。 。
In summary, I don't think you should .gitignore
the file in this situation. 总而言之,在这种情况下,我认为您不应该
.gitignore
文件。 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. 关于git中被忽略文件的语义的微妙之处使我无数次-被忽略的文件被认为是一次性的 ,因为该机制是为构建产品而设计的。 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.
您所拥有的是一个您要忽略的文件,但是它很宝贵,而git当前没有指定该文件的方法。
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! 例如,在您的情况下,如果您手动重新创建
index.php
,则看起来一切正常,但是如果您使用git checkout old-commit
移回到跟踪index.php
的旧版本,然后转到回到以前的位置,通过git checkout -
,您的index.php
将被删除!
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: 我建议您更改
index.php
以从其他一些文件中为环境变量获取正确的设置:
Ideally, then also add a default value for when that other file doesn't exist. 理想情况下,然后为该其他文件不存在时添加一个默认值。
This is an old question, but I do this as well and have struggled with it in the past. 这是一个古老的问题,但我也这样做,并且过去一直在努力。
What is happening is that since index.php wasn't originally in your .gitignore, index.php is being tracked by all of your repositories. 发生的事情是,由于index.php最初不在您的.gitignore中,因此所有存储库都将跟踪index.php。
When you updated the .gitignore on your development site and removed it from your repository, what it does is passed the "deleted index.php" to your production site. 当您在开发站点上更新.gitignore并将其从存储库中删除时,其作用是将“已删除的index.php”传递给生产站点。 If your production site is still missing index.php on ITS .gitignore, it will "delete" index.php as it should.
如果您的生产站点仍在ITS .gitignore上缺少index.php,它将按需“删除” index.php。
What you then have to do is ensure you add index.php to every .gitignore on every branch of every repository. 然后,您要做的是确保将index.php添加到每个存储库每个分支上的每个.gitignore中。 THEN you can use rm --cached and everything will work as expected.
然后,您可以使用rm --cached,一切都会按预期进行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.