规则引擎 设计 git

by Wassim Chegham

由Wassim Chegham

引擎盖下的Git (Git under the hood)

Let’s explore some common Git commands, and dive into its internals to see what Git does when you run them.

让我们探索一些常见的Git命令,并深入了解其内部,看看运行它们时Git会做什么。

But first, let’s talk about Git itself.

但首先,让我们谈谈Git本身。

什么是Git? (What is Git?)

Put simply, Git is an open source distributed version control system. It was designed by Linus Torvalds, creator of the Linux kernel, to manage the source code of the kernel. So Git was designed from the start to be as fast and efficient as possible.

简而言之,Git是一个开源的分布式版本控制系统。 它是由Linux内核的创建者Linus Torvalds设计的,用于管理内核的源代码。 因此,Git从一开始就被设计为尽可能快速高效。

Git原则 (Git’s Principles)

In other version control systems such as CVS, Subversion, and ClearCase, the server is centralized — there’s a clear separation between the server and clients.

在其他版本控制系统(例如CVS,Subversion和ClearCase)中,服务器是集中式的-服务器与客户端之间存在明显的分隔。

When developers work on projects that use these systems, they first send a “checkout” request to the server, then retrieve a “snapshot” of the current version — usually the most recent one. Everyone has to go through the central server in order to work on the same project, sending “commits” or creating branches.

当开发人员在使用这些系统的项目上工作时,他们首先向服务器发送“签出”请求,然后检索当前版本(通常是最新版本)的“快照”。 每个人都必须经过中央服务器才能处理同一项目,发送“提交”或创建分支。

With Git, things are different. When you ask for a project, you clone it locally on to your machine.

使用Git,情况就不同了。 当您请求一个项目时,可以将其本地克隆到您的计算机上。

In other words, Git copies all the project files to your hard drive, then allows you to work on the project autonomously. All operations run locally on your machine. You don’t even need a network connection, except to synchronize with the source code by “pushing” or “pulling.”

换句话说,Git将所有项目文件复制到您的硬盘驱动器,然后允许您自主地处理项目。 所有操作都在计算机上本地运行。 您甚至不需要网络连接,只需通过“推”或“拉”与源代码同步即可。

That’s what makes Git so quick.

这就是让Git如此之快的原因。

With Git, you can:

使用Git,您可以:

  • “commit” your changes“提交”您的更改
  • change and create branches更改并创建分支
  • “merge” branches“合并”分支
  • retrieve a “diff” or apply a “patch”检索“差异”或应用“补丁”
  • recover different versions of any file恢复任何文件的不同版本
  • access the change history of any file访问任何文件的更改历史记录

And you can do all this without even being connected to Internet. Amazing, right?

而且,您无需连接到Internet就可以完成所有这些操作。 太好了吧?

工作流程示例 (An example workflow)

Let’s take a web application generated with Yeoman (don’t worry if you’re unfamiliar with this tool — it does not matter).

让我们看一下用Yeoman生成的Web应用程序(不用担心,如果您不熟悉此工具-没关系)。

Once Yeoman scaffolds out the application, creating its file tree structure, run git status. Git will respond that the current directory is not a Git repository:

一旦Yeoman搭建了应用程序,并创建了文件树结构,请运行git status。 Git会回答当前目录不是Git存储库:

So you need to run the git init command in the root directory in order to initialize a Git repository.

因此,您需要在根目录中运行git init命令以初始化Git存储库。

As you can see from the screen shot, we created an empty Git repository, and we are currently on its main branch — usually called “master.”

从屏幕快照中可以看到,我们创建了一个空的Git存储库,并且当前位于其主分支(通常称为“主”)上。

You can also notice that Git creates a .git folder at the root of the repo. This hidden directory is Git’s database. If you wish to make a backup of your project, simply make a tar.gz (or zip) of this directory.

您还可以注意到,Git在存储库的根目录下创建了一个.git文件夹。 这个隐藏的目录是Git的数据库。 如果要备份项目,只需在该目录下创建一个tar.gz (或zip )。

Let’s run git status to see our status:

让我们运行git status来查看我们的状态:

Git tells us that we haven’t added anything to our commit yet. So let us add the content of the current directory with the git add command:

Git告诉我们我们还没有添加任何内容。 因此,让我们使用git add命令添加当前目录的内容:

Before you commit your changes, you should check what you’re about to commit. To do that, run git diff:

在提交更改之前,您应该检查要提交的内容。 为此,运行git diff

Git tells us that we have changes waiting to be committed. Let’s commit them using the command git commit -m “first commit”:

Git告诉我们,我们有更改要等待提交。 让我们使用命令git commit -m“ first commit”提交它们:

Now let’s see how Git allows us to work on different features at the same time by using multiple branches.

现在,让我们看看Git如何允许我们通过使用多个分支同时处理不同的功能。

To illustrate this, we’ll open another terminal in the same directory, and run our application:

为了说明这一点,我们将在同一目录中打开另一个终端,然后运行我们的应用程序:

In order to create a new branch in Git, we use the verb “checkout” (with the -b flag):

为了在Git中创建一个新分支,我们使用动词“ checkout”(带有-b标志):

So we just created a new branch called “branch_A” and changed the current working context from the “master” branch to the “branch_A” branch.

因此,我们刚刚创建了一个名为“ branch_A”的新分支,并将当前的工作上下文从“ master”分支更改为“ branch_A”分支。

Any changes we make will only affect the current branch. Let’s make some changes to the home page of our application, such as changing the background color:

我们所做的任何更改只会影响当前分支。 让我们对应用程序的主页进行一些更改,例如更改背景色:

By running git status, we notice that we have some pending changes:

通过运行git status ,我们注意到我们有一些未完成的更改:

Let’s add this edited file and commit:

让我们添加这个编辑后的文件并提交:

Using the git branch command, we can see what branch we’re in. To go back to the “master” branch, we can type git checkout master.

使用git branch命令,我们可以看到我们所在的分支。回到“ master”分支,我们可以输入git checkout master。

After switching branches, we can see that— in the terminal where we launched our application — that the content of the file we modified in the branch “branch_A” has been reloaded and replaced by that of the branch “master” file:

切换分支后,我们可以看到-在启动应用程序的终端中-在分支“ branch_A”中修改的文件内容已被重新加载,并由分支“主”文件替换:

Please note that Git does not allow you to change your branch if you have pending changes. So if you really need to switch branches with pending changes, you can first ask Git to put aside those changes for you, using the git stash command:

请注意,如果您有未决的更改,Git不允许您更改分支。 因此,如果您确实需要使用待处理的更改来切换分支,则可以首先使用git stash命令让Git为您保留这些更改:

You then have the option of applying those changes later using:

然后,您可以选择以后使用以下选项来应用这些更改:

$ git stash apply stash@{0}

This will apply the first backup — because you specified {0}.

这将应用第一个备份-因为您指定了{0}。

When you’re working with several branches, at some point you will want to copy all the changes from one branch to another. Thankfully, Git has a git merge command that can do just that. Let’s merge branch_A into our current working branch, master:

当您使用多个分支时,有时需要将所有更改从一个分支复制到另一个分支。 幸运的是,Git有一个git merge命令可以做到这一点。 让我们将branch_A合并到当前的工作分支master中:

The good news: Git allows you to merge the same branch more than once. For example, imagine that you edit some files in branch_A, then merge them into “master.” Then you edit again branch_A again. Git does not prevent you from merging branch_A into master a second time.

好消息:Git允许您多次合并同一分支。 例如,假设您在branch_A中编辑了一些文件,然后将它们合并为“ master”。 然后,再次编辑branch_A。 Git不会阻止您第二次将branch_A合并到master。

现在让我们看看Git如何完成所有这些工作 (Now let’s look at how Git does all this)

Let’s assume that our project contains two files: BlogFactory.js and BlogController.js.

让我们假设我们的项目包含两个文件:BlogFactory.jsBlogController.js。

When we create our local repo with git clone or git init, Git initializes its database, and saves it in a hidden directory called .git:

当我们使用git clonegit init创建本地存储库时,Git会初始化其数据库,并将其保存在名为.git的隐藏目录中:

If we examine this folder, we see the presence of several subdirectories and files. The most interesting one are:

如果我们检查此文件夹,则会看到存在多个子目录和文件。 最有趣的是:

  • HEAD: this file contains the path to the reference that indicates the current branch

    HEAD :此文件包含指向当前分支的引用的路径

  • config: the repo configuration file

    config :仓库配置文件

  • objects: this is the directory that contains all the repo files, their content is encoded and compressed

    objects :这是包含所有回购文件的目录,其内容经过编码和压缩

  • refs / heads: this directory contains a file per branch. Each file is named after a branch, and its content is the SHA1 of the last commit (as explained below)

    refs / heads :此目录每个分支包含一个文件。 每个文件都以一个分支命名,其内容为最后一次提交的SHA1(如下所述)

When you create or edit files, you need to run:

创建或编辑文件时,需要运行:

$ git add BlogFactory.js BlogController.js

Or:

要么:

$ git add . # in order to add all unstagged files

This command tells Git that you want to add a snapshot of your files. So Git retrieves the current state of the contents of your files, then computes their checksums using SHA1, and creates an entry in its database. The key of this entry is the SHA1 hash, and its value is the raw contents of the file.

该命令告诉Git您要添加文件快照。 因此,Git检索文件内容的当前状态,然后使用SHA1计算其校验和,并在其数据库中创建一个条目。 此项的键是SHA1哈希,其值是文件的原始内容。

Yes, all the content!

是的,所有内容!

Then, as we said earlier, you need to commit these changes. To do that, you run the command:

然后,正如我们之前所说,您需要提交这些更改。 为此,运行命令:

$ git commit -m "A very useful commit message"

At this point, Git records a sort of “manifest” representing the whole file structure tree, with each filename and its SHA1 key in its database. Then it calculates the checksum of this manifest, based on its contents. Then it links to the new commit.

此时,Git记录了一种表示整个文件结构树的“清单”,其中每个文件名及其SHA1密钥都在其数据库中。 然后,它根据清单的内容计算清单的校验和。 然后,它链接到新的提交。

Now imagine that you have changed the BlogController.js file, and you redo a git add. Git performs the same process as before. It creates a new entry in its database, and because the file contents have changed, the SHA1 checksum has also changed.

现在,假设您已经更改了BlogController.js文件, 并重做git add。 Git执行与以前相同的过程。 它在数据库中创建一个新条目,并且由于文件内容已更改,因此SHA1校验和也已更改。

Then, when you do a git commit, Git recreates a new manifest with the new entry SHA1:

然后,当您执行git commit时 ,Git用新条目SHA1重新创建一个新清单:

Now suppose that you rename your file to MyBlogController.js for instance, and then commit your changes again. Git does not create a new entry in the database since the content—and the SHA1—have not changed:

现在,假设您将文件重命名为MyBlogController.js ,例如,然后再次提交更改。 Git不会在数据库中创建新条目,因为内容和SHA1均未更改:

Here’s what’s actually happening in the Git database:

这是Git数据库中实际发生的事情:

Git has stored the content of both committed files in the directory .git/ objects. Beside those committed files, Git also saves a file containing the details of the commit, and a manifest file as described above.

Git已将两个已提交文件的内容存储在目录.git / object中 。 除了这些提交的文件,Git还保存了一个包含提交细节的文件和一个清单文件,如上所述。

The Git command cat-file -p SHA1 is used to read the content of the stored objects. The SHA1 hash is composed of the first two bits of the directory objects/XX/ with another 38-bits forming the name of the object objects/XX/YY..YY. For example:

Git命令cat-file -p SHA1用于读取存储对象的内容。 SHA1哈希由目录对象/ XX /的前两位组成,另外38位构成对象对象/XX/YY..YY的名称。 例如:

$ git cat-file -p 987451acde8030ef93abaaff87daa617316cc7c7

You can also enter the first 8 bits of the SHA1 (those actually are enough):

您还可以输入SHA1的前8位(实际上已经足够):

$ git cat-file -p 987451ac

Similarly, the content of the object storing the information of the commit looks like this:

同样,存储提交信息的对象的内容如下所示:

As you can see, the commit object file contains some information related to that commit, including the SHA1 of manifest (tree), which looks like this:

如您所见,提交对象文件包含与该提交有关的一些信息,包括清单(树)的SHA1,如下所示:

So as you may have guessed, Git does not really care about file names. It cares more about their content. Even if you copy a file, Git will not create a new entry in its database. It’s just a matter of content and SHA1 hashes.

因此,您可能已经猜到了,Git并不真正在乎文件名。 它更关心他们的内容。 即使您复制文件,Git也不会在其数据库中创建新条目。 这只是内容和SHA1哈希值的问题。

And if you’re wondering: when I do a git push, what does Git really do? Well, Git computes the delta between the two files, compresses it, and then send it to the server. Git does not send the file’s entire content.

而且,如果您想知道:当我执行git push时, Git到底在做什么? 好吧,Git计算两个文件之间的增量,将其压缩,然后将其发送到服务器。 Git不会发送文件的全部内容。

翻译自: https://www.freecodecamp.org/news/git-internals-for-curious-developers-a1e44e7ecafe/

规则引擎 设计 git

规则引擎 设计 git_引擎盖下的Git相关推荐

  1. 基于Event Sourcing和DSL的积分规则引擎设计实现案例

    架构设计模式(Architecture Patterns),是"从特殊到普遍"的.基于各种实际问题的解决方案而总结归纳出来的架构设计最佳实践,是一种对典型的.局部的架构逻辑的高度抽 ...

  2. 如何构建营销活动平台(四):规则引擎设计

    前言 前面将活动抽象成了规则检验和一系列的操作,不同的活动的规则有重叠也有不同,如何设计才能保证最好的扩展性. 规则引擎的出现就是制定一套规则检验的模型,下面来看下具体的设计. 核心UML图 组件介绍 ...

  3. 规则引擎 java 设计_规则引擎设计

    最近用到了规则引擎 ,简单做一个总结. 规则,说白了,就是,现状(fact)怎么样,如果(condition)怎么样,那么(action)怎么样. 规则引擎使用了rete算法,我这边使用的是drool ...

  4. .Net Core 环境下构建强大且易用的规则引擎

    1. 引言 1.1 为什么需要规则引擎 在业务的早期时代,也许使用硬编码或者逻辑判断就可以满足要求.但随着业务的发展,越来越多的问题会暴露出来: 逻辑复杂度带来的编码挑战,需求变更时改变逻辑可能会引起 ...

  5. 规则引擎选型及应用 邴越 2017-04-27 16:31:17 浏览614 评论0 HTTPS 模块 配置 string exception void input 规则引擎 摘要: 规则引擎具体执

    规则引擎选型及应用 邴越 2017-04-27 16:31:17 浏览614 评论0 HTTPS 模块 配置 string exception void input 规则引擎 摘要: 规则引擎具体执行 ...

  6. drools规则引擎技术指南_物联网规则引擎技术

    物联网应用程序设计与典型的IT解决方案大不相同,因为它将物理操作技术(OT)与传感器.致动器和通信设备连接起来,并将数字信息技术(IT)与数据.分析和工作流连接起来. 在企业环境中,物联网非常复杂,这 ...

  7. java风控系统规则引擎_如何设计一套规则引擎系统

    很早之前就想写一篇关于「规则引擎」的文章,但是一直苦于没有时间.刚好最近给团队小伙伴梳理了我设计的引擎的使用和原理,正好借此机会在此写下我们的心得. 「规则引擎」系统一般而言,在风控中使用较多,但是经 ...

  8. 复杂风控场景下,如何打造一款高效的规则引擎

    | 在互联网时代,安全已经成为企业的命脉.美团信息安全团队需要采用各种措施和手段来保障业务安全,从而确保美团平台上的用户和商户利益不会受到侵害. 本文主要介绍了美团在打造自有规则引擎Zeus(中文名& ...

  9. 规则引擎 drools_网易考拉规则引擎平台架构设计与实践

    背景 考拉安全部技术这块目前主要负责两块业务:一个是内审,主要是通过敏感日志管理平台搜集考拉所有后台系统的操作日志,数据导入到es后,结合storm进行实时计算,主要有行为查询.数据监控.事件追溯.风 ...

最新文章

  1. Java多线程--使用future进行异步编程
  2. gitlab 修改git clone地址为指定域名
  3. 如何在Android Studio里关掉instant run
  4. php sql获取字段名称,mssql获取字段名及注释,以及一系列问题
  5. python中合并列表_关于python:如何将两个列表合并到一个列表中?
  6. 远程办公 4 大坑,坑坑“致命”!
  7. 轻松解决U盘拷贝文件时提示文件过大问题
  8. 建筑企业收并购系列二:股转与吸收合并
  9. PPT修改幻灯片大小
  10. 计算机丢失quartz.dll什么意思,计算机中丢失quartz.dll解决方法
  11. ZXR10交换机命名规则
  12. python怎么识别log函数_log函数图像_函数图像_python函数图像 - 云+社区 - 腾讯云
  13. 罗斯蒙特3051常见故障解决方案
  14. 分享一个上传照片,并且可以分享的网址
  15. OCR读取身份证地址字符串切割成省、市、区
  16. 苹果Mac系统无法输入密码怎样解决
  17. 快排法(模版型)与归并法
  18. IT行业个人职业发展
  19. 如何自动校正系统时间
  20. 我和王争学设计模式|工厂方法

热门文章

  1. 系统学Android从零开始,详细的Android学习指南
  2. 配电柜测试软件,低压配电柜测试方法及流程.docx
  3. Java中key可以重复的Map集合:IdentityHashMap
  4. JavaWeb--JavaEE
  5. mysql数据库中case when 的用法
  6. 总结verilog产生随机数的$random和seed
  7. Docker学习笔记 - Docker Compose
  8. 进程间的通讯(IPC)方式
  9. SpringMVC学习记录--Validator验证分析
  10. unity3d 预制体