日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

规则引擎 设计 git_引擎盖下的Git

發(fā)布時(shí)間:2023/11/29 编程问答 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 规则引擎 设计 git_引擎盖下的Git 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

規(guī)則引擎 設(shè)計(jì) 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命令,并深入了解其內(nèi)部,看看運(yùn)行它們時(shí)Git會(huì)做什么。

But first, let’s talk about Git itself.

但首先,讓我們談?wù)凣it本身。

什么是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.

簡(jiǎn)而言之,Git是一個(gè)開源的分布式版本控制系統(tǒng)。 它是由Linux內(nèi)核的創(chuàng)建者Linus Torvalds設(shè)計(jì)的,用于管理內(nèi)核的源代碼。 因此,Git從一開始就被設(shè)計(jì)為盡可能快速高效。

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.

在其他版本控制系統(tǒng)(例如CVS,Subversion和ClearCase)中,服務(wù)器是集中式的-服務(wù)器與客戶端之間存在明顯的分隔。

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.

當(dāng)開發(fā)人員在使用這些系統(tǒng)的項(xiàng)目上工作時(shí),他們首先向服務(wù)器發(fā)送“簽出”請(qǐng)求,然后檢索當(dāng)前版本(通常是最新版本)的“快照”。 每個(gè)人都必須經(jīng)過中央服務(wù)器才能處理同一項(xiàng)目,發(fā)送“提交”或創(chuàng)建分支。

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

使用Git,情況就不同了。 當(dāng)您請(qǐng)求一個(gè)項(xiàng)目時(shí),可以將其本地克隆到您的計(jì)算機(jī)上。

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將所有項(xiàng)目文件復(fù)制到您的硬盤驅(qū)動(dòng)器,然后允許您自主地處理項(xiàng)目。 所有操作都在計(jì)算機(jī)上本地運(yùn)行。 您甚至不需要網(wǎng)絡(luò)連接,只需通過“推”或“拉”與源代碼同步即可。

That’s what makes Git so quick.

這就是讓Git如此之快的原因。

With Git, you can:

使用Git,您可以:

  • “commit” your changes

    “提交”您的更改
  • change and create branches

    更改并創(chuàng)建分支
  • “merge” branches

    “合并”分支
  • retrieve a “diff” or apply a “patch”

    檢索“差異”或應(yīng)用“補(bǔ)丁”
  • recover different versions of any file

    恢復(fù)任何文件的不同版本
  • 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應(yīng)用程序(不用擔(dān)心,如果您不熟悉此工具-沒關(guān)系)。

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搭建了應(yīng)用程序,并創(chuàng)建了文件樹結(jié)構(gòu),請(qǐng)運(yùn)行g(shù)it status。 Git會(huì)回答當(dāng)前目錄不是Git存儲(chǔ)庫(kù):

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

因此,您需要在根目錄中運(yùn)行g(shù)it init命令以初始化Git存儲(chǔ)庫(kù)。

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.”

從屏幕快照中可以看到,我們創(chuàng)建了一個(gè)空的Git存儲(chǔ)庫(kù),并且當(dāng)前位于其主分支(通常稱為“主”)上。

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在存儲(chǔ)庫(kù)的根目錄下創(chuàng)建了一個(gè).git文件夾。 這個(gè)隱藏的目錄是Git的數(shù)據(jù)庫(kù)。 如果要備份項(xiàng)目,只需在該目錄下創(chuàng)建一個(gè)tar.gz (或zip )。

Let’s run git status to see our status:

讓我們運(yùn)行g(shù)it status來查看我們的狀態(tài):

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告訴我們我們還沒有添加任何內(nèi)容。 因此,讓我們使用git add命令添加當(dāng)前目錄的內(nèi)容:

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

在提交更改之前,您應(yīng)該檢查要提交的內(nèi)容。 為此,運(yùn)行g(shù)it 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.

現(xiàn)在,讓我們看看Git如何允許我們通過使用多個(gè)分支同時(shí)處理不同的功能。

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

為了說明這一點(diǎn),我們將在同一目錄中打開另一個(gè)終端,然后運(yùn)行我們的應(yīng)用程序:

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

為了在Git中創(chuàng)建一個(gè)新分支,我們使用動(dòng)詞“ checkout”(帶有-b標(biāo)志):

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.

因此,我們剛剛創(chuàng)建了一個(gè)名為“ branch_A”的新分支,并將當(dāng)前的工作上下文從“ 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:

我們所做的任何更改只會(huì)影響當(dāng)前分支。 讓我們對(duì)應(yīng)用程序的主頁進(jìn)行一些更改,例如更改背景色:

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

通過運(yùn)行g(shù)it status ,我們注意到我們有一些未完成的更改:

Let’s add this edited file and commit:

讓我們添加這個(gè)編輯后的文件并提交:

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:

切換分支后,我們可以看到-在啟動(dòng)應(yīng)用程序的終端中-在分支“ branch_A”中修改的文件內(nèi)容已被重新加載,并由分支“主”文件替換:

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:

請(qǐng)注意,如果您有未決的更改,Git不允許您更改分支。 因此,如果您確實(shí)需要使用待處理的更改來切換分支,則可以首先使用git stash命令讓Git為您保留這些更改:

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

然后,您可以選擇以后使用以下選項(xiàng)來應(yīng)用這些更改:

$ git stash apply stash@{0}

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

這將應(yīng)用第一個(gè)備份-因?yàn)槟付藍(lán)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:

當(dāng)您使用多個(gè)分支時(shí),有時(shí)需要將所有更改從一個(gè)分支復(fù)制到另一個(gè)分支。 幸運(yùn)的是,Git有一個(gè)git merge命令可以做到這一點(diǎn)。 讓我們將branch_A合并到當(dāng)前的工作分支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允許您多次合并同一分支。 例如,假設(shè)您在branch_A中編輯了一些文件,然后將它們合并為“ master”。 然后,再次編輯branch_A。 Git不會(huì)阻止您第二次將branch_A合并到master。

現(xiàn)在讓我們看看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.

讓我們假設(shè)我們的項(xiàng)目包含兩個(gè)文件:BlogFactory.js和BlogController.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:

當(dāng)我們使用git clone或git init創(chuàng)建本地存儲(chǔ)庫(kù)時(shí),Git會(huì)初始化其數(shù)據(jù)庫(kù),并將其保存在名為.git的隱藏目錄中:

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

如果我們檢查此文件夾,則會(huì)看到存在多個(gè)子目錄和文件。 最有趣的是:

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

    HEAD :此文件包含指向當(dāng)前分支的引用的路徑

  • config: the repo configuration file

    config :倉(cāng)庫(kù)配置文件

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

    objects :這是包含所有回購(gòu)文件的目錄,其內(nèi)容經(jīng)過編碼和壓縮

  • 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 :此目錄每個(gè)分支包含一個(gè)文件。 每個(gè)文件都以一個(gè)分支命名,其內(nèi)容為最后一次提交的SHA1(如下所述)

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

創(chuàng)建或編輯文件時(shí),需要運(yùn)行:

$ 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檢索文件內(nèi)容的當(dāng)前狀態(tài),然后使用SHA1計(jì)算其校驗(yàn)和,并在其數(shù)據(jù)庫(kù)中創(chuàng)建一個(gè)條目。 此項(xiàng)的鍵是SHA1哈希,其值是文件的原始內(nèi)容。

Yes, all the content!

是的,所有內(nèi)容!

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

然后,正如我們之前所說,您需要提交這些更改。 為此,運(yùn)行命令:

$ 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.

此時(shí),Git記錄了一種表示整個(gè)文件結(jié)構(gòu)樹的“清單”,其中每個(gè)文件名及其SHA1密鑰都在其數(shù)據(jù)庫(kù)中。 然后,它根據(jù)清單的內(nèi)容計(jì)算清單的校驗(yàn)和。 然后,它鏈接到新的提交。

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.

現(xiàn)在,假設(shè)您已經(jīng)更改了BlogController.js文件, 并重做了git add。 Git執(zhí)行與以前相同的過程。 它在數(shù)據(jù)庫(kù)中創(chuàng)建一個(gè)新條目,并且由于文件內(nèi)容已更改,因此SHA1校驗(yàn)和也已更改。

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

然后,當(dāng)您執(zhí)行g(shù)it commit時(shí) ,Git用新條目SHA1重新創(chuàng)建一個(gè)新清單:

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:

現(xiàn)在,假設(shè)您將文件重命名為MyBlogController.js ,例如,然后再次提交更改。 Git不會(huì)在數(shù)據(jù)庫(kù)中創(chuàng)建新條目,因?yàn)閮?nèi)容和SHA1均未更改:

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

這是Git數(shù)據(jù)庫(kù)中實(shí)際發(fā)生的事情:

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已將兩個(gè)已提交文件的內(nèi)容存儲(chǔ)在目錄.git / object中 。 除了這些提交的文件,Git還保存了一個(gè)包含提交細(xì)節(jié)的文件和一個(gè)清單文件,如上所述。

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用于讀取存儲(chǔ)對(duì)象的內(nèi)容。 SHA1哈希由目錄對(duì)象/ XX /的前兩位組成,另外38位構(gòu)成對(duì)象對(duì)象/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位(實(shí)際上已經(jīng)足夠):

$ git cat-file -p 987451ac

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

同樣,存儲(chǔ)提交信息的對(duì)象的內(nèi)容如下所示:

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:

如您所見,提交對(duì)象文件包含與該提交有關(guān)的一些信息,包括清單(樹)的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.

因此,您可能已經(jīng)猜到了,Git并不真正在乎文件名。 它更關(guān)心他們的內(nèi)容。 即使您復(fù)制文件,Git也不會(huì)在其數(shù)據(jù)庫(kù)中創(chuàng)建新條目。 這只是內(nèi)容和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.

而且,如果您想知道:當(dāng)我執(zhí)行g(shù)it push時(shí), Git到底在做什么? 好吧,Git計(jì)算兩個(gè)文件之間的增量,將其壓縮,然后將其發(fā)送到服務(wù)器。 Git不會(huì)發(fā)送文件的全部?jī)?nèi)容。

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

規(guī)則引擎 設(shè)計(jì) git

總結(jié)

以上是生活随笔為你收集整理的规则引擎 设计 git_引擎盖下的Git的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。