开发者

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. 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 CodeIgni开发者_Python百科ter 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.


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.

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. If your production site is still missing index.php on ITS .gitignore, it will "delete" index.php as it should.

What you then have to do is ensure you add index.php to every .gitignore on every branch of every repository. THEN you can use rm --cached and everything will work as expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜