使用git进行测试和生产服务器设置

使用git进行测试和生产服务器设置

本文介绍了使用git进行测试和生产服务器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是GIT的新手.我有一个生产URL,另一个有开发URL,我想将新代码推送到该URL.

I am new to GIT. I have one production url and another as development url to which i want to push the new code.

开发: http://development.myrepo.something

制作: http://production.myrep.something

现在,我通常在不同的计算机上工作.我需要一个设置,在该设置中,我实际上可以将我的所有工作从不同的计算机推送到开发url,当我满意时,我在生产url中推送相同的内容.

Now i usually work from different computers. I need a setup in which i can actually push all my work to the development url from different computers and when i get satisfied, i push the same thing in production url.

我做了这么多的事情

  1. 在两个URL上复制了完全相同的文件.此时,两个URL在浏览器中都给我相同的结果.

  1. Copied exactly same files on both the URLS. At this point both the URL's give me same result in broswer.

在两个目录中均执行git init,并将其设置为git repos.

Executed git init in both the directories and made them git repos.

因此,我想我现在可以在本地工作,然后进行开发回购;如果满意,我可以再次进行生产回购.

So at thie point i thought, i can now work on local and then push to the development repo and when satisfied i can push again to the production repo.

但是它不能像我每次按下一样工作,它会向我显示错误,因为存储库没有裸露.

But it doesn't work as whenever i push, it shows me the error because the repos aren't bare.

那我现在该怎么办?

我正在考虑从该链接中采用分支方法

I am thinking to follow the branching approach from this Link

但是问题是我想在开发分支中查看/测试服务器上的工作.使用上面链接中提到的方法,我只能在执行合并后才能看到.

But the problem is that i want to see/test the work on the server in the development branch. With the approach mentioned in the above link, i can only see after the merge has been performed.

请阐明一些正确的方向.

Please shed some light and point me in the right direction.

推荐答案

您的服务器上有一个 bare 存储库作为生产代码的存储,并在它附近的某个地方设置了另一个非裸存储库,将从裸机中拉出 进行测试.不要尝试对付git.

Have a bare repository on your server as a storage for production code, and setup a second non-bare repository somewhere near it which will pull from the bare one for testing. Dont' try to work against git.

这个想法是,如果您使用存储库实际在其中写入代码,那么您就不应该使用它.

The idea is that if you are using a repository to actually write code in it, then you shouldn't push to it.

因此,首先为代码创建一个存储库:

So, first you create a repo for your code:

$ cd /path/to/dir/with/dev/repo
$ git init --bare

这是您将用作开发代码集中存储的存储库,可以通过 http 或其他任何方式从外部看到此存储库.您可以在工作库中将其配置为远程的"dev"(或原始").

This is the repo you'll use as a central storage of your dev code, this one will be visible from the outside via http or whatever. You configure it as "dev" (or "origin") remote in your working repos.

因此,同样,您刚刚配置的存储库是仅推/拉式存储库,您实际上并未在其中进行任何工作:您在其克隆中编写代码,然后推送您的更改.即使您碰巧在同一台计算机上工作,也只需克隆:

So, again, the repo you just configure is a push/pull-only repo, you don't actually do work in it: you write code in its clones and then push your changes. Even if you happen to work on the same machine, just clone:

$ cd /path/to/work/dir
$ git clone /path/to/dir/with/dev/repo

完成后将更改推回.

这同样适用于您的生产"存储库.您为生产代码 storage 设置了一个裸存储库,然后,如果要对其进行测试或在服务器上进行部署,则只需将其克隆到同一服务器上的非裸存储库中即可.有一个测试仓库.

The same applies to your "production" repo. You set up a bare repository for production code storage, and then if you want to test it or deploy on the server, you just clone it to a non-bare repo on the same server—now you've got a repo for testing.

如果您希望在推送到存储库时自动部署代码,有许多教程介绍了如何使用hoos实现此功能(此处其中一个).

If you want your code to be deployed automatically when you push to a repo, there are a number of tutorials explaining how to achieve this with hoos (here is one of them).

这篇关于使用git进行测试和生产服务器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 17:27