团队如何正确的对git进行部署
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:31:53
0
3
613

本人学生党,现在和几个同学一起开发,打算用git

目前git搭建好裸仓库了,并且hooks可以自动同步到web项目中.

由于服务器上的代码不是仓库,现在想要将原先另一个服务器上的代码导入到裸仓库上,然后供团队成员去pull。该如何做?自己想到的办法就是先将代码拉到本地,然后再从本地push到中央仓库,由于做了自动同步,所以中央仓库则自动将push的代码同步到web项目。但个人感觉应该有更好的方法。求告知?

还有就是一般git的使用仓库是整个项目吗?还是项目中的部分?如果是整个项目,用户上传图片那岂不是每次更新还要将上传的图片更新到本地。

查了挺久资料的,也很少讲这方面的,求各位大神详解。

===========================

您好,就现在我们团队在项目中出现了一个问题就是,由于5.1期间项目出了个bug,有个同学在家里修改了bug,但他的电脑没装git,所以使用ftp上传了。现在由于使用ftp上传所以没有使用到中央仓库自然就没有触发到hooks的post-reveice也就不会push到网站项目中(有点绕,望大神能理解),所以现在使用git就无法获取拉取到他所上传的那一部分。所以现在的问题就是我要写多一个hooks,网站项目上的一旦改变(如果是ftp上传的)则pull到中央仓库,然后本地才能获取。做到中央仓库和网站项目能双向同步。可能我们这种做法不太好,但是目前暂时只能这么做,当然也希望大神回答是顺带提供下好的方法。再次谢过

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
Ty80

The description of the problem is not very clear, so I will briefly describe what I understand.

The method of migrating code is no problem.
Generally, the warehouse used by git is the entire project, which may contain some submodules.
The user uploading pictures you mentioned is actually another issue. Have you synchronized the git project warehouse to the server and used it as the directory of the web project?

If so, there will be a little problem. First of all, a better approach is that the git warehouse is only used for development. As for publishing and deploying web projects, use Jenkins and other tasks to do it. The specific process is:

  1. Project developers trigger github's webhook through operations, such as pushing code, tagging, etc.

  2. Github requests your deployment tool based on the webhook configuration and notifies your deployment tool to further perform the release action.

  3. The deployment tool pulls the latest code to the code directory, packages the web project through scripts or commands, generates a new web project directory, and publishes it to the server.
    In this case, the user's pictures are uploaded to the project directory in the server instead of the git code directory, so there is no need to worry about updating the uploaded pictures.

In addition, there may be security issues when using a code repository to publish as a web project. If access rights are not well controlled, others may obtain the files in your git project, which may leak some information.

漂亮男人

The method you mentioned is a very good method. The two remote warehouses cannot directly communicate with each other and need to be transferred.

User images, caches, etc. must of course be ignored. Only valid codes are stored in the warehouse.

PHPzhong

Actually.gitthe folder contains all the information, you can copy it directly. But git has commands to do this

$ git clone --bare my_project my_project.git
Cloning into bare repository 'my_project.git'...
done.

This operation is basically the same as the following operation:

$ cp -Rf my_project/.git my_project.git

Then upload the obtained my_project.git to the server where the bare warehouse is located (replace the folder). The git documentation gives a very detailed introduction:
Git-on-the-Server-Getting-Git-on-a-Server.

As for the second question, feel free to add the entire project to git for management, including resource files, documents, etc. This will make it easier for teams to collaborate. But do not include the files generated by compilation. This is set through .gitignore. As for the issue of updating pictures, if the picture is a resource to be used in this project, then it will naturally need to be fetched. There is no problem.

There are also teams that add the automatically generated IDE configuration under the project to the version management. If the team members all use the same IDE, they can share the settings. This is a matter of wisdom.

============

Wait a minute, why "The central warehouse automatically synchronizes the push code to the web project", I think you should be referring to the running web service. The build server should have an unmodified local warehouse and actively send it to the code warehouse pull,然后根据最新的代码启动构建,根据构建出来的结果刷新Web服务或者打包。这个动作可以由hooks触发,但公共的代码仓库不应该发起push.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template