git 设置有效目录

The code was working yesterday but today it is not

该代码昨天有效,但今天却没有

The code got deleted

代码被删除

A weird bug has been introduced suddenly and no-one knows how

突然引入了一个奇怪的错误,没人知道如何

If you have been in any of the above situations then this post is for you.

如果您曾经遇到以上任何情况,那么此职位适合您

Apart from knowing git add, git commit , and git push , there are a bunch of other important techniques in Git. Knowing these will help a lot in the long run. Here I will be covering some of the things which will enable you to make the best use of Git.

除了了解git addgit commitgit pushgit push还有很多其他重要技术。 从长远来看,了解这些将大有帮助。 在这里,我将介绍一些使您能够充分利用Git的东西。

Git工作流程 (Git workflows)

Whenever multiple developers are involved in a project it is necessary to use the right workflow for Git. Here I will be covering one workflow which is very effective in big projects with multiple developers.

只要有多个开发人员参与一个项目,就有必要为Git使用正确的工作流程。 在这里,我将介绍一种工作流程,该工作流程在具有多个开发人员的大型项目中非常有效。

情境 (Scenario)

All of a sudden you have become the tech lead for a project in which you are planning to build the next Facebook. The team has three developers:

突然之间,您已成为计划建立下一个Facebook的项目的技术主管。 该团队有三位开发人员:

  1. Alice: has one year of experience and knows programming

    爱丽丝 :拥有一年的经验,并且了解编程

  2. Bob: has one year of experience and knows programming

    鲍勃 :有一年的经验,并且了解编程

  3. John: has 3 years of experience and knows programming well

    约翰 :拥有3年经验,并且精通编程

  4. You: assigned as tech lead for this project

    您:被指定为该项目的技术负责人

Git中的开发过程 (Development process in Git)

主分支 (Master branch)

  1. The Master Branch should always have a copy of the existing code in Production.主分支应始终具有生产中现有代码的副本。
  2. No-one — including the tech lead — should be coding directly in the master branch since it is a copy of production code.

    没有人( 包括技术负责人)应直接在master分支中进行编码,因为它是生产代码的副本。

  3. The actual code is written in other branches.实际代码是在其他分支中编写的。

发布分支 (Release branch)

  1. When the project begins the first thing to do is to create a release branch for the project. The release branch is created from the master branch.

    项目开始时,要做的第一件事就是为项目创建一个发布分支 。 release分支是从master分支创建的。

  2. All code pertaining to this project will be in the release branch. The release branch is just a normal branch with the prefix release/.

    与该项目有关的所有代码都将在release分支中。 release分支只是前缀为release /的普通分支。

  3. Let’s call the release branch for this example release/fb.

    让我们将此示例release / fb称为release分支

  4. It’s possible that there are multiple projects running on the same code base. So, for each project, a separate release branch is created. Let’s say there is one more project running in parallel. Then that project can have a separate release branch like release/messenger

    同一代码库上可能有多个项目正在运行。 因此,对于每个项目,都会创建一个单独的发行分支。 假设还有一个并行运行的项目。 然后,该项目可以有一个单独的发行分支,例如release / messenger

  5. The reason to have a release branch is that the same code base can have multiple projects running in parallel — there should be no conflict between the projects.拥有发布分支的原因是,相同的代码库可以有多个并行运行的项目-项目之间应该没有冲突。

功能分支 (Feature branch)

  1. For every feature that is built in the application a separate feature branch is created. This ensures that the features can be built independently

    对于应用程序中内置的每个功能,都会创建一个单独的功能分支 。 这样可以确保可以独立构建功能

  2. Feature branch is just like any other branch but with the prefix feature/

    功能分支与其他任何分支一样,但带有前缀feature /

  3. Now you, being the tech lead, have asked Alice to build a login screen for Facebook. So she creates a new feature branch for this. Lets call the feature branch feature/login. Alice would write the entire login code only in this feature branch.

    现在,作为技术负责人,您已经要求Alice为Facebook构建登录屏幕。 因此,她为此创建了一个新的功能分支。 让我们调用功能分支功能/登录。 爱丽丝只会在此功能分支中写入整个登录代码。

  4. The feature branch is generally created from the release branch

    功能分支通常是从发布分支创建的

  5. Bob has been tasked with building the “Friend” request page. So Bob creates a feature branch called feature/friendrequest

    Bob的任务是建立“好友”请求页面。 因此,鲍勃创建了一个名为Feature / Friendrequest的功能分支

  6. John’s task is to build the news feed. So John creates a feature branch called feature/newsfeed

    John的任务是建立新闻源。 因此,约翰创建了一个名为Feature / newsfeed的功能分支

  7. All of the developers code in their individual feature branches. So far so good.所有开发人员都在各自的功能分支中进行编码。 到目前为止,一切都很好。
  8. Now, let’s say that Alice finished her task and the login code is ready. She needs to send her code to the release branch release/fb from her feature branch feature/login. This is done through a pull request.

    现在,假设爱丽丝完成了她的任务,并且登录代码已准备就绪。 她需要将其代码从功能分支功能/登录发送到发布分支release / fb 这是通过请求请求完成的。

拉取要求 (Pull request)

First and foremost, a pull request is not to be confused with git pull .

首先,不要将pull请求与git pull混淆。

The developer cannot push the code directly into the release branch. The tech lead needs to review the feature code before it goes into the release branch. This is done through a pull request.

开发人员无法将代码直接推送到发行分支。 技术负责人需要在进入发布分支之前检查功能代码。 这是通过请求请求完成的。

Alice can raise the pull request as follows in GitHub — these steps are specifically for GitHub.

爱丽丝可以在GitHub中按以下方式提出拉取请求-这些步骤专门针对GitHub。

Right next to the branch name there is an option called “New pull request”. Clicking on this opens a new screen shown below:

分支名称旁边有一个名为“ New pull request”的选项。 单击此按钮将打开一个新屏幕,如下所示:

Here:

这里:

  • the compare branch should be Alice’s feature branch feature/login

    比较分支应该是爱丽丝的功能分支功能/登录

  • the base branch should be the release branch release/fb.

    基本分支应该是发布分支release / fb。

Once this is done, Alice needs to enter a title and description for the pull request, and finally click on “Create Pull Request”. Alice also needs to assign a reviewer for this pull request. She enters your name as the reviewer since you are the tech lead.

完成此操作后,Alice需要输入请求请求的标题和说明,最后单击“创建请求请求”。 爱丽丝还需要为此请求请求分配审阅者。 由于您是技术主管,因此她输入您的姓名作为审阅者。

The tech lead then reviews the code in the pull request, and merges the code from the feature branch into the release branch

然后,技术负责人检查请求请求中的代码,并将代码从功能分支合并到发布分支中

So now you have merged the code from the feature/login branch to the release/fb branch and Alice is pretty happy that her code has been merged.

因此,现在您已将功能/登录分支中的代码合并到发布/ fb分支中,而爱丽丝很高兴自己的代码已被合并。

代码冲突。 (Code Conflicts.)

  1. Bob has completed his code as well, and has raised a pull request from feature/friendrequest to release/fb.

    鲍勃还完成了他的代码,并提出了从feature / friendrequestrelease / fb的拉取请求。

  2. Since the release branch already has the login code, code conflicts occur. It is the responsibility of the reviewer to resolve these code conflicts and merge the code. In this case, you as the tech lead need to resolve these code conflicts and merge the code.

    由于发布分支已经具有登录代码,因此发生代码冲突 。 审阅者有责任解决这些代码冲突并合并代码。 在这种情况下,您作为技术主管需要解决这些代码冲突并合并代码。

  3. Now John has also completed his code and wants to add his code to the release branch. But John is pretty good at handling code conflicts. John takes the Latest code from release/fb branch into his own feature branch feature/newsfeed ( either through git pull or git merge ). John resolves all the conflicts that are present. Now the feature/newsfeed branch has all the code present in release/fb as well.

    现在,约翰还完成了他的代码,并希望将其代码添加到发布分支。 但是John非常擅长处理代码冲突。 John将release / fb分支中的最新代码带到自己的功能分支feature / newsfeed中 (通过git pullgit merge )。 约翰解决了所有存在的冲突。 现在, feature / newsfeed分支也具有release / fb中存在的所有代码。

  4. Finally, John raises a pull request. This time there are no code conflicts in the pull request since John has already resolved them.最后,约翰提出了拉取请求。 由于John已经解决了它们,因此这次的pull请求中没有代码冲突。

So there are two ways to resolve code conflicts:

因此,有两种方法可以解决代码冲突:

  • First method: the reviewer of the pull request needs to resolve the code conflicts.第一种方法:拉取请求的审阅者需要解决代码冲突。
  • Second method: the developer ensures that latest code from the release branch is merged into the feature branch and resolves the conflicts themselves.第二种方法:开发人员确保将release分支中的最新代码合并到feature分支中,并自行解决冲突。

再次主分支 (Master branch again)

Once the project is completed, the code from the release branch is merged back into the master branch. The code is then deployed to production. Thus, the code in production and the code in the master branch are always in sync. This also ensures that, for any future project, the up-to-date code is available in master.

项目完成后,来自发行分支的代码将合并回分支。 然后将代码部署到生产中。 因此,生产中的代码和master分支中的代码始终保持同步。 这也确保了对于以后的任何项目,最新代码都可以在master中获得

参考文献 (References)

More information about pull requests is here.

有关请求请求的更多信息,请参见此处 。

恭喜

git 设置有效目录_如何有效使用Git相关推荐

  1. SVN Git 设置忽略目录 大全

    eclipse中SVN设置 用svn控制版本,svn本身是不会识别哪些该传,哪些不该传,这就导致有些关于路径的东西(比如拓展jar的路径)也被上传了,而当别人下载后,那个路径对于这个人可能完全不存在, ...

  2. bash git 如何切换目录_【git】命令行与本地仓库/远程仓库

    终端里如何复制粘贴 在cmder里 粘贴是鼠标右键 粘贴时shift+Insert 复制是用鼠标选中即自动复制 在Git Bash里 粘贴是鼠标中键 粘贴时shift+Insert 复制是用鼠标选中, ...

  3. 将整个表单设置为只读_如何将Git的界面语言设置为中文?

    我们从官网下载安装好 Git 客户端后,打开软件默认的是英文,那如果我们想要设置成我们熟悉的中文,那该怎么设置呢?随W3Cschool编程狮一起看看吧~ 以下操作环境为 Windows10 64位 1 ...

  4. git钩子放服务器_如何使用Git 钩子来自动化开发和部署任务

    介绍 版本控制已成为现代软件开发的中心要求. 它允许项目安全地跟踪更改,启用撤销,完整性检查和协作等好处. 在git的版本控制系统,特别是,已由于其分散式架构,并在它可以使和转让方之间变化的速度看到广 ...

  5. git stage 暂存_什么是Git?下载和安装Git

    3. 使用git管理代码 3.1 什么是git? git ==git: 开源的分布式版本控制系统,也可以用于内容管理== git的作用 工作区:就是你在电脑里能看到的目录. 暂存区:英文叫stage, ...

  6. git 命令详解_再次学习Git版本控制工具

    微信公众号:PHP在线 Git 究竟是怎样的一个系统呢?为什么在SVN作为版本控制工具已经非常流行的时候,还有Git这样一个版本控制工具呢?Git和SVN的区别在哪儿呢?Git优势又在哪呢?下面PHP ...

  7. git进入项目目录 windows_Windows下搭建Git服务器

    Windows平台下搭建Git服务器的图文详解及教程 Git没有客户端服务器端的概念,但是要共享Git仓库,就需要用到SSH协议(FTP , HTTPS , SFTP等协议也能实现Git共享,此文档不 ...

  8. git clone 多个_如何通过Git参与项目开发

    Git介绍 QA& 小白 Git 是什么? Git是一个开源的免费的分布式版本管理系统,最初是由Linux内核发明人Linus Torvalds用于管理Linux内核开发而开发的. 大神 小白 ...

  9. git merging 怎么处理_如何让 Git 的输出对代码更友好?

    关注公众号 "OpenSourceDaily" ,每天推荐给你优秀开源项目 大家好,我是欧盆索思(opensource),每天为你带来优秀的开源项目! 如今 Git 是每个开发人员 ...

最新文章

  1. 设计模式之适配器模式(Adapter)摘录
  2. 云计算(2)it 是什么
  3. postman设置域名_Postman中文文档——证书(Certificates)
  4. torch_geometric笔记:nn. graclus (图点分类)
  5. python断言assert实例_Python断言assert的用法代码解析
  6. 判断输入的数是否质数,求范围内的质数有哪些
  7. 15-[JavaScript]-ECMAScript 1
  8. 06 ansible剧本功能实践介绍
  9. Service startService方式的服务
  10. mysql导出一行数据类型_MySQL 导出数据
  11. CSS实现限制字数功能
  12. T2Admin 完美集成 RDP报表(含:菜单、权限系统)
  13. C语言error2005,关于ERROR LNK 2005错误
  14. 制作QQ微信支付宝三合一收款码
  15. 讲课大师 把微信消息同步转发到企业微信中
  16. 计算机仿真在线投稿系统,常见问题解决-计算机仿真官方投稿系统.doc
  17. M2BEV:采用统一BEV表征的多摄像头联合3D检测分割
  18. 个人投资——基本原则
  19. 根据首字母排序英文名c语言,英文名按首字母排序的问题
  20. FPGA未来硬件架构探讨-NoC

热门文章

  1. python示例异常处理与程序调试_笔记:Python异常处理与程序调试
  2. 苹果禁止使用热更新 iOS开发程序员新转机来临
  3. Java高级特性增强-多线程
  4. cnblogs不愧为cnblogs
  5. dubbo学习过程、使用经验分享及实现原理简单介绍
  6. 阿里巴巴一年投三家AR公司,AR购物或是最终目标
  7. 多线程读一个全局变量要不要加锁?还是说只是当修改全局变量的时候才要加锁?...
  8. 使用文本用户界面(NMTUI)进行网络配置
  9. 在SQL Server 2008中配置文件流(FILESTREAM)
  10. codility上的问题 (22)