当前位置: 首页 > 编程日记 > 正文

git 设置有效目录_如何有效使用Git

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.

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

恭喜😄 (Congrats 😄)

You now know how to make the best use of Git. Git has some other concepts like amending commits, and rebasing which are also useful. But Git workflow is pretty important for big projects to be successful.

您现在知道如何充分利用Git。 Git还有其他一些概念,例如修改提交和重新设置基准,这些概念也很有用。 但是, Git工作流程对于大型项目的成功至关重要。

关于作者 (About the author)

I love technology and follow the advancements in technology. I also like helping others with any knowledge I have in the technology space.

我热爱技术,并追随技术的进步。 我也喜欢以我在技术领域拥有的任何知识来帮助他人。

Feel free to connect with me on my LinkdIn account https://www.linkedin.com/in/aditya1811/

随时通过我的LinkdIn帐户与我联系https://www.linkedin.com/in/aditya1811/

You can also follow me on twitter https://twitter.com/adityasridhar18

您也可以在Twitter上关注我https://twitter.com/adityasridhar18

My Website: https://adityasridhar.com/

我的网站: https : //adityasridhar.com/

Best Practises while using Git

使用Git时的最佳做法

Here is my introduction to Git.

这是我对Git的介绍 。

翻译自: https://www.freecodecamp.org/news/how-to-use-git-efficiently-54320a236369/

git 设置有效目录

相关文章:

C\C++宏大全

一、标准预定义宏The standard predefined macros are specified by the relevant language standards, so they are available with all compilers that implement those standards. Older compilers may not provide all of them. Their names all start with double undersc…

POJ 3630 Phone List

题目大意:给n个字符串,问是否有一个是另一个的前缀思路:把n个字符串插到trie里,然后判断就好&#xff0c;注意一个长字符串覆盖另一个短字符串和短字符串匹配长字符串的区别 1 #include<iostream>2 #include<cstring>3 #include<cstdio>4 #define maxn 10000…

微信小程序地图标记点,点击标记点显示详细信息源码加效果图

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 效果图&#xff1a; 实现代码: <!-- <text>{{markers[id].placeName}}</text> --> <block wx:if{{isshow}}><map id"map" longitude"114.048410" latit…

如何仅使用HTML和JavaScript构建简单的URL缩短器

by Palash Bauri由Palash Bauri 如何仅使用HTML和JavaScript构建简单的URL缩短器 (How to build a simple URL shortener with just HTML and JavaScript) You might have used a URL shortener before, such as bit.ly, goo.gl. They are useful for shortening long URLs so…

hibernate中的hql查询语句list查询所有与iterate查询所有的区别

hibernate中的hql查询语句list查询所有与iterate查询所有的区别 list查询所有&#xff1b; 01&#xff0c;会立即产生一条select语句1select查询出来的所有语句都会被session管理&#xff0c; 保 存在缓存中 02&#xff0c;清空或者不清空session缓存中的数据&#xff0c;再次…

php解决 mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysq

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 The mysql extension is deprecated and will be removed in the future: use mysq 翻译&#xff1a; mysql_connect这个模块将在未来弃用&#xff0c;请你使用mysqli或者PDO来替代。 解决方法&#x…

Test execution order

刚开始的时候&#xff0c;JUnit并没有规定测试方法的调用执行顺序。方法通过映射的API返回的顺序进行调用。然 而&#xff0c;使用JVM顺序是不明智的&#xff0c;因为Java平台没有规定任何特定的顺序&#xff0c;事实上JDK7或多或少的返回的是随机顺序。大部分写的好的测试代码…

您需要了解有关Angular中的ng-template,ng-content,ng-container和* ngTemplateOutlet的所有信息...

It was one of those days when I was busy working on new features for my office project. All a sudden, something caught my attention:那是我忙于为Office项目开发新功能的日子之一。 突然间&#xff0c;一些事情引起了我的注意&#xff1a; While inspecting the DOM …

洛谷P2587 [ZJOI2008]泡泡堂

传送门 1368 泡泡堂 省队选拔赛 时间限制: 1 s空间限制: 128000 KB题目等级 : 大师 Master题解题目描述 Description第XXXX届NOI期间&#xff0c;为了加强各省选手之间的交流&#xff0c;组委会决定组织一场省际电子竞技大赛&#xff0c;每一个省的代表队由n名选手组成&#xf…

bootstrap的日期选择器 完整源码demo附效果图

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 效果图&#xff1a; &#xff08;点击图1时钟显示图2自动隐藏图1&#xff0c;点击图2的日历会显示图1自动隐藏图2&#xff09; 源码 <!DOCTYPE html> <html><head><meta charset&q…

redux 局部刷新_如何使用Redux Observables和刷新令牌API获取新的访问令牌

redux 局部刷新by Sachin Kumar由Sachin Kumar 如何使用Redux Observables和刷新令牌API获取新的访问令牌 (How to get a new access token using Redux observables and the refresh token API) This article is about how I handled a 401 status code on an API response. …

九宫格抽奖转盘源码分析

效果如上图所示&#xff0c;下面对其实现代码进行分析&#xff0c;看能不能破解其抽奖规则。需要引入jquery-1.8.3.min.js和images/9张图片。 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tra…

关于使用strtok的一个小问题

今天在弄一下啊小小程序的时候。报错&#xff0c;出现了问题。先看代码 int main(int argc, char* argv[]) {char *filename "interface_ipset_1_1.json";char* split1 "_";char* split2 ".";char splitfile1[4][NAME_MAX];sagent_string_sp…

微信小程序发送模板消息,php发送模板消息

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 formId 在安卓系统是纯数字&#xff0c;在IOS系统是一串加密字符&#xff0c;如图&#xff1a; 发送模板消息&#xff08;服务通知&#xff09;效果图&#xff1a; 前端 wxml <form bindsubmit"…

使用TypeScript映射和条件类型使React组件更出色

by Deepu K Sasidharan通过Deepu K Sasidharan 使用TypeScript映射和条件类型使React组件更出色 (Make your React components great with TypeScript mapped and conditional types) You’ve probably heard about TypeScript. You may have heard someone claiming how grea…

2017年6月16号课堂笔记

2017年6月16号 星期五 空气质量&#xff1a;中度污染~轻度污染 内容&#xff1a;jQuery&#xff1a;remove&#xff0c;bind&#xff0c;attr&#xff0c;on和live&#xff0c;同辈和父辈节点的操作&#xff0c; keyup/keypress/keydown,focus-blur应用&#xff0c;表单事件/键…

大宗商品(Bulk Stock)交易

大宗商品&#xff08;Bulk Stock&#xff09;是指可进入流通领域&#xff0c;但非零售环节&#xff0c;具有商品属性用于工农业生产与消费使用的大批量买卖的物质商品。在金融投资市场&#xff0c;大宗商品指同质化. 可交易. 被广泛作为工业基础原材料的商品大宗商品电子交易主…

【Ant Design Pro 二】 创建页面,组件,并在页面调用

开发交流qq群 173683895 路由里面的参数作用介绍: {path: "/a_nowdayserver/nowdayserver", //随便取名,显示在访问路径url中,如果是子路由,需要和父路径匹配icon: "file", //菜单栏显示的图标name: "你好", //菜单栏显示的标题component…

安卓收取费用_作为自由职业者应收取的费用:以价值为基础的定价是否能达到炒作的目的?...

安卓收取费用by Benek Lisefski由Benek Lisefski 作为自由职业者应收取的费用&#xff1a;以价值为基础的定价是否能达到炒作的目的&#xff1f; (What to charge as a freelancer: does value-based pricing live up to the hype?) 定价很难。 (Pricing is hard.) Even afte…

Java笔记(25):设计模式概述

1、设计模式的概述和分类 设计模式&#xff1a; 经验的总结。 A:创建型 创建对象 B:结构型 对象的组成 C:行为型 对象的功能创建型模式&#xff1a;1)简单工厂模式 2)工厂方法模式 3)设计模式 2、简单工厂模式概述和使用 1 package cn.itcast_01; 2 3 public abstract class A…

Ant Design Pro 使用图表 charts bizcharts

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 淌了一下午坑,都是辛酸泪 总结:首先要知道, 它不能直接使用 charts ,需要安装 bizcharts 插件,然后导入 bizcharts 中的 charts; 点击跳转到 bizcharts 官方文档,建议看完整个流程再跳转 首先,…

【剑指offer 面试题47】不用加减乘除做加法

思路&#xff1a; 利用位运算 C&#xff1a; 1 #include <iostream>2 using namespace std;3 4 int main()5 {6 int a 11, b 17;7 int sum, carry;8 do9 { 10 sum a ^ b; 11 carry (a & b) << 1; 12 a sum; 13 …

travis-ci自动部署_如何使用Travis CI部署(几乎)零恐惧的Cloud Foundry应用

travis-ci自动部署by Robin Bobbitt罗宾波比(Robin Bobbitt) 如何使用Travis CI部署(几乎)零恐惧的Cloud Foundry应用 (How to deploy your Cloud Foundry app with (almost) zero fear using Travis CI) Application deployments to the cloud should be painless. We should…

Activiti 规则任务(businessRuleTask)

Activiti 规则任务&#xff08;businessRuleTask&#xff09; 作者&#xff1a;邓家海 目前国内研究Activiti规则任务businessRuleTask&#xff09;的文章在网上应该不超出3篇 小觑夜漫酒作伴&#xff0c;破晓黎明当笑言 前言&#xff1a; 最近一直在研究Activiti工作流的自动化…

10年工作经验老程序员推荐的7个开发类工具

做.NET软件工作已经10年了&#xff0c;从程序员做到高级程序员&#xff0c;再到技术主管&#xff0c;技术总监。见证了Visual Studio .NET 2003,Visul Studio 2005, Visual Studio Team System 2008, Visual Studio 2010 Ultimate,Visual Studio 2013一系列近5个版本的变化与亲…

PHP SSL certificate: unable to get local issuer certificate的解决办法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 当本地curl需要访问https时&#xff0c;出现SSL certificate: unable to get local issuer certificate错误信息 解决办法&#xff1a; 到http://curl.haxx.se/ca/cacert.pem下载pem文件&#xff0c;并…

辞职前为什么挣扎_当您感到自己像开发人员一样挣扎时,为什么学得最多

辞职前为什么挣扎by Walt Schlender由Walt Schlender 当您感到自己像开发人员一样挣扎时&#xff0c;为什么学得最多 (Why you learn the most when you feel like you’re struggling as a developer) The times when I have made the greatest leaps in my development skil…

Hadoop学习之Mapreduce执行过程详解

一、MapReduce执行过程 MapReduce运行时&#xff0c;首先通过Map读取HDFS中的数据&#xff0c;然后经过拆分&#xff0c;将每个文件中的每行数据分拆成键值对&#xff0c;最后输出作为Reduce的输入&#xff0c;大体执行流程如下图所示&#xff1a; 整个流程图具体来说&#xff…

汇编试验十五:安装新的int 9中断例程

安装新的int 9中断例程&#xff08;按A键后显示满屏幕的A&#xff09; int 9 是外中断&#xff0c;同样&#xff0c;程序编写还是和其他中断例程类似&#xff0c;安装&#xff08;复制&#xff09;&#xff0c;调用&#xff1b; 不同点是在于&#xff0c;他要从端口读取数据60h…

php判断前端传的多个字段与数据库匹配

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码 <?phpheader("Content-Type:text/html;charsetutf8"); header("Access-Control-Allow-Origin: *"); //解决跨域header(Access-Control-Allow-Methods:POST);// 响应类型 …