简体   繁体   English

使用GIT进行Java网站版本控制的最佳方法是什么

[英]What is the best way to use GIT for versioning Java Website

I have a git repo installed in my unix for version tracking our Java EE website. 我的Unix中安装了一个git repo,用于跟踪我们的Java EE网站的版本。

I have currently run into issues not in the usage of git but the way in which I am suppose to use it which is explained below. 我目前遇到的问题不是git的用法,而是我想使用它的方式,下面将对此进行说明。

I work in a team of 3 developers which contribute to the website development. 我以一个由3个开发人员组成的团队工作,他们为网站开发做出了贡献。

Initially when I installed Git in our server I directly created a repo of our webapps directory which contains the actual work files and ran into the foll problems. 最初,当我在服务器中安装Git时,我直接创建了webapps目录的存储库,其中包含实际的工作文件,并遇到了问题。

1)While committing the changes into the repo one of us would genrally do a git add . 1)虽然将更改提交到仓库中,但我们当中的一个通常会执行git add . and commit it to the repository which would commit not only the files the commiter changed but would also commit the changes of other developers. 并将其提交到存储库中,该存储库不仅将提交提交者更改的文件,而且还将提交其他开发人员的更改。

When we faced this issue we decided that we needed to create separate non-bare repos for each one of us in the same server in different directories which would house the entire code.The basic work stucture we are following is hown below: 当我们面对这个问题时,我们决定需要在同一服务器的不同目录中为我们每个人创建单独的非裸仓库,以存放整个代码。我们遵循的基本工作结构如下:

在此处输入图片说明

As shown above in the image we have created a bare repo which would have the website contents pushed by the webapps which in the image is the Work Directory. 如上图所示,我们创建了一个裸仓库,其中的网站内容由webapp推送,该webapp在图中为Work Directory。

The basic workflow here is: 这里的基本工作流程是:

1) Create n number of non-bare repos for each and every developer. 1)为每个开发人员创建n个非裸仓库。

2) Get the entire website work files from pulling from that bare repo 2)从该裸仓库中提取整个网站工作文件

3) After making changes to our own repo push to the bare repo 3)更改我们自己的仓库后,推送到裸仓库

4) The bare repo being configured with a post-receive hook would actually update the Work Directory. 4)配置有接收后挂钩的裸仓库实际上将更新工作目录。

This setup is working fine but we are facing a lot of issues as shown below: 此设置运行良好,但我们面临许多问题,如下所示:

1) Each developer having his own contetnts in a separate directory is not able to test the code before pushing it to the bare repo which would update the Work Directory- Coz of these steps even for say one jsp file change I end up doing 20 commits until it starts working properly without bugs since we have tomcat pointing to only the original work directory. 1)每个开发人员在单独的目录中都有自己的竞争者,无法在将代码推送到裸仓库之前对其进行测试,这将更新Work Directory- Coz的这些步骤,即使说一个jsp文件更改我最终要进行20次提交直到它开始正常运行而没有错误为止,因为我们tomcat仅指向原始工作目录。

This has become the most troubleseme issue here. 这已成为这里最麻烦的问题。

This strategy has solved the issue of conflicts which was there before but created even a greater issue regarding testing the code. 该策略解决了以前存在的冲突问题,但在测试代码方面甚至产生了更大的问题。

How can we improve this scenario where using GIT in out project seems benefitial. 在外出项目中使用GIT似乎有益的情况下,我们如何改善这种情况。

Can anyone suggest any ways for improving the same. 任何人都可以提出任何改进方法的建议。

Maybe a strategy like this might work? 也许这样的策略可能行得通? I've used a similar strategy before with a small team and it worked well for us: 我在一个小型团队中使用过类似的策略,它对我们来说效果很好:

  • Each developer creates a branch before making any changes. 每个开发人员在进行任何更改之前都会创建一个分支。
  • Developer does some work and commits to their branch 开发人员进行一些工作并提交到他们的分支
  • If possible, developers run tomcat (or jetty, or whatever) against their own directory to test. 如果可能的话,开发人员针对自己的目录运行tomcat(或jetty或其他工具)进行测试。 Maven makes this really easy. Maven使这变得非常容易。
  • Before pushing, developers rebase their branches against master 在推销之前,开发人员将分支机构与master相结合
  • Developers push their branch to bare repo 开发人员将分支推向裸仓库
  • Then you (or whoever is in charge of final approval), merges the branch into master. 然后,您(或负责最终批准的人)将分支合并为主分支。 If the developers rebase correctly, this should be a simple fast forward merge. 如果开发人员正确地调整了基准,这应该是一个简单的快速向前合并。

Updated with some ideas about how each developer might run webapp: 更新了有关每个开发人员如何运行webapp的一些想法:

There are a few ways I can think of to accomplish the 3rd bullet point above: 我可以想到几种方法来实现上述第三个要点:

  • Use a single installation of tomcat. 使用单个安装的tomcat。 Create multiple contexts, one for each developer. 创建多个上下文,每个开发人员一个。

    For example, for developer1, create a context file named dev1.xml under tomcat_home/conf/catalina/localhost with something similar to: 例如,对于developer1,在tomcat_home / conf / catalina / localhost下创建一个名为dev1.xml的上下文文件,其内容类似于:

    ?xml version="1.0" encoding="UTF-8"?> Context path="/dev1" docBase="/home/developer1/wars/your-webapp-1.0.war" unpackWAR="false"/> ?xml version =“ 1.0” encoding =“ UTF-8”?>上下文路径=“ / dev1” docBase =“ / home / developer1 / wars / your-webapp-1.0.war” unpackWAR =“ false” />

    (note I removed the first '<' so xml will appear in the post) (请注意,我删除了第一个“ <”,因此xml将出现在帖子中)

  • Use jetty to run the war using command line, something like: 使用码头通过命令行进行战争,例如:

    java -jar jetty-runner.jar your-webapp-1.0.war java -jar jetty-runner.jar your-webapp-1.0.war

  • Use mechanisms provided by a build tool like ant, or maven to run and test the webapp. 使用由ant或maven之类的构建工具提供的机制来运行和测试Webapp。 For example, in maven you can use the jetty-plugin to run the webapp using mvn jetty:run , or even configure it to start a webserver and run tests each time you build the project. 例如,在maven中,您可以使用jetty插件通过mvn jetty:run来运行Web应用程序,甚至可以将其配置为启动Web服务器并在每次构建项目时运行测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM