0% found this document useful (0 votes)
6 views52 pages

Lecture6 - Version Control (Git)

mising semeser in CS lecture6

Uploaded by

eastern8ird
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views52 pages

Lecture6 - Version Control (Git)

mising semeser in CS lecture6

Uploaded by

eastern8ird
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

2023/5/11 15:40 For print

Lecture 6: Version Control (git) (2020)


Time Subtitle Machine Translation
1s alright let's get started with today's 好吧,让我们开始今天的 讲座,实际上
lecture so actually before we get 在我们
6s started one quick note about office hours 开始之前,关于办公时间的一个简短说
it seemed from the poll that some 明, 从民意调查来看,似乎有些
10s people were under the impression that 人的印象是 每次讲座之后的办公时间
the office hours that follows each
12s lecture is just about that day's lectures 只是关于当天的 讲座主题,这不是 这种
topics and this is not the case 情况下,
17s you can come to office hours and ask us 您可以来办公时间问我们 关于任何讲座
questions about any lecture whether it's 的问题,无论是
21s the previous day or from the previous 前一天还是前 一周,甚至是
week or even things not exactly covered
24s in this class that you're just curious about 本课程中没有完全涵盖的您只是好奇的
so yeah come to office hours with 事情, 所以是的,来办公时间提出
28s questions about anything office hours are 问题 任何办公时间都 在 32 g9 休息室所
in the 32 g9 lounge so building 32 以 32 号楼
36s also known as a Stata Center has two 也被称为 Stata 中心有两座 塔 G 塔和 D
towers the G tower and the D tower so 塔所以
40s we're in the gates tower on the ninth floor 我们在九楼的门塔 所以如果你一直乘电
so if you take the elevator all 梯
43s the way up there's the lounge right in 休息室就在 你们面前好酷所以今天我们
front of you okay cool so today we're
50s going to be talking about version control 要谈论版本 控制系统所以我只想
systems so I just want to get a
53s sense of whether you guys have used 了解一下你们以前是否使用过 版本控制
version control systems before so could 系统所以
58s you raise your hand if you have any 如果你有请举手 任何 使用 git 或任何其
experience with git or any other version 他版本
1:01 control system like subversion or 控制系统(如 subversion 或 mercurial
mercurial or anything else oh great so 或其他任何东西)的经验哦,太好了,
1:05 that's a good number of you so I won't 你们中有很多人所以我不会
talk about version control systems in
1:10 general way too much then we'll pretty 过多地谈论版本控制系统,然后我们 很
quickly get into the details of git and 快就会进入 git 的详细信息以及
1:14 like it's data model and its internals but 它的数据模型及其内部结构, 但作为快
just as a quick summary version 速摘要版本
1:19 control systems are tools that are used to 控制系统是用于 跟踪源代码
keep track of changes to source code

about:blank 1/52
2023/5/11 15:40 For print

1:23 or other collections of files or folders and 或其他文件或文件夹集合的更改的工具


as the name implies these tools help ,顾名思义,这些工具有助于
1:28 track the history of changes to some set 跟踪 对某些文档集的更改历史记录 ,除
of documents and in addition to doing 此之外,
1:33 that they facilitate collaboration so they're 它们还促进协作,因此 它们对于与一
really useful for working with a
1:38 group of people on a software project 组人一起处理软件项目非常有用 Virna 控
Virna control systems track changes to a 制系统
1:43 folder and its contents in a series of 在一系列快照中跟踪文件夹及其内容的
snapshots so you capture the entire 更改 所以你捕获一个
1:48 state of a folder and everything inside like 文件夹的整个状态和里面的所有东西,
a software project and you have 就像一个软件项目,你
1:51 multiple of these in a series of snapshots 在一系列快照中有多个这样的 快照,每
each snapshot encapsulate the 个快照封装了
1:56 entire set of files and folders contained 一些顶级目录中包含的整个文件和文件
within some top-level 夹集
1:58 directory and then version control ,然后版本控制 系统也 维护一堆元
systems also maintain a bunch of
2:02 metadata along with the actual changes 数据以及对内容的实际更改, 这样就可
to the content and this is to make it 以
2:06 possible to figure things out like who 弄清楚是谁对
authored a particular change to a
2:10 particular file or when was a particular 特定文件进行了特定更改,或者何时 进
change made 行了特定更改,
2:13 and slow version control systems 而缓慢的版本控制系统会 像作者一样维
maintain metadata like authors and 护元数据 和
2:16 commit timestamps and you can also 提交时间戳,您还可以将 额外的消息附
attach extra messages to these 加到这些快照
snapshots
2:21 and things like that and so why is version 和类似的东西,那么为什么 版本控制
control useful
2:25 well it's useful even when you're working 非常有用它甚至在您 自己处理项目时也
on projects by yourself so you 很有用,因此您
2:29 can use it to look at old versions of code 可以使用它来查看旧版本的 代码 通过查
you've written figure out like why 看提交消息,
2:32 something was changed by looking at 通过
commit messages work on different
things
2:36 in parallel without conflicts by using 使用 不同的开发分支,在不发生冲突的
different branches of development or be 情况下并行处理不同的事情,或者
2:41 able to work on bug fixes while keeping 能够在修复错误的同时保持 对不同功能
work on different features independent 独立的事情的工作,
2:44 things like that and so it's an invaluable 这样的事情是 一个 非常宝贵的工具,即
tool even if you're working
about:blank 2/52
2023/5/11 15:40 For print

使你是一个
2:48 just by yourself even on a small scale 人在一个小规模的 项目上工作,就像我
project like I think the instructors of 认为
2:53 this course use git even on things like 本课程的讲师甚至在 家庭作业或课堂项
homework assignments or class projects 目之类的事情上使用 git,
2:58 even small scale things in addition to our 即使是除了 我们的研究或更大的软件项
research or larger software projects 目之外的小规模的事情
3:01 and then of course version control is a 当然,版本控制是 与其他人合作的一个
really powerful tool for working with 非常强大的工具,
3:06 other people so it's useful for sending 因此
patches of code around resolving
3:11 conflicts when different people are 当不同的人同时 处理同一段代码时,它
working on the same piece of code at the 对于发送代码补丁来解决冲突非常有
用,
3:15 same time things like that and so it's a 所以它真的是一个 用于您
really powerful tool for working by
3:20 yourself or with others and it also has a 自己或与他人合作的强大工具,它还有
neat functionality to let you answer 一个简洁的功能,可以让您回答一些
3:25 questions that would otherwise be kind of 否则 很难回答的问题,例如谁
hard to answer like who wrote a
3:28 particular module in a software project or 在软件项目中编写了特定模块 或谁编辑
who edited a particular line in a 了特定软件中的特定行
3:32 particular software project why was this 项目 为什么这个 特定的行改变了 什么时
particular line change when was it 候被谁
3:36 changed by whom things like that and 改变了 诸如此类的事情和 版本控制系统
version control systems also have some 也有一些
3:41 really powerful functionality that we might 非常强大的功能,我们 可能会在今天的
cover at the end of today's 讲座结束时介绍这些功能,
3:44 lecture or you can find the lecture notes if 或者如果我们没有时间,您可以找到讲
we 义
3:46 don't have time to do things like 做一些事情,比如 应该有一些你
supposed to have some project you've
3:49 been working on for a couple years and 已经工作了几年的项目, 然后你注意到
then you notice that some funny thing 这个项目的一些有趣的事情
3:52 about the project was broken like you 被打破了,就像你 有一些单元测试不再
have some unit test that doesn't pass 通过
3:54 anymore and it wasn't broken just now it 并且它没有被打破 就在 不久前它被打破
was broken some time ago and you don't 了,你不
3:58 know exactly when this regression was 知道这个回归是什么时候 引入的,写得
introduced well written control systems 很好的控制系统
4:03 have a way of automatically identifying 有一种自动识别 它的方法,就像你可以
this like you can take it and give it a 接受它并给它一个

about:blank 3/52
2023/5/11 15:40 For print

4:07 unit test that's currently failing but you 单元测试,当前失败但 你知道正在通过
know was passing at some point in 在过去的某个时候,
4:11 the past and it can binary search your 它可以对你的历史进行二进制搜索, 并
history and figure out exactly what 准确地找出
4:15 change to your code made it break so 你的代码发生了什么变化导致它崩溃,
lots of really powerful fancy features 所以
4:19 if you know how to use these tools 如果你知道如何正确使用这些工具,那
properly 么很多非常强大的奇特功能就会
4:25 there are a number of version control 出现许多版本控制系统 get 已经成为
systems out there and get has become
4:30 kind of the de facto standard for version 版本控制的事实上的标准,所以这就是
control so that's what we're 我们
4:33 going to be covering in today's lecture 今天的讲座要讲的内容 我想给你看一部
one comic I want to show you which was 漫画,
4:39 on the screen before hand let me bring it 之前在屏幕上放过,让我把 它放回去,
back up so this is an xkcd comic that 所以这是 一个 xkcd 漫画
4:47 illustrates gets reputation so let me read 说明获得了声誉所以让我 大声读给你
it out loud for you
4:52 this is good it tries collaborative work on 这是很好它尝试 通过一个漂亮的
projects through a beautiful
4:56 distributed graph theory tree model cool 分布式图论树模型在项目上进行协作工
how do we use it no idea just memorize 作很酷 我们如何使用它不知道只是记住
5:01 these shell commands and type them to 这些 shell 命令并将它们输入到 如果出现
sync up if you get errors save your work 错误,请同步 将您的工作保存
5:05 elsewhere delete the project and 在别处 删除项目并 下载一个新副本,所
download a fresh copy so maybe some 以也许有些
5:11 people may not want to raise their hands 人可能不想 为此举手,但如果您
for this but raise your hand if you've
5:14 ever done this before I certainly have 曾经这样做过,请举手, 我在学习时肯
when I was learning 定有过
5:17 this tool so good number of you here 这个工具在座的很多人 以前都用过,所
have done this before so the goal of 以
5:22 this lecture is to make it so you don't 本次讲座的目的是让它成为现实, 不幸
have to do this anymore unfortunately as 的是,你不必再这样做了,因为
5:27 this comic illustrates gets interface is a 这部漫画说明了获取界面是 一个设计非
pretty terribly designed interface 常糟糕的界面,
5:34 it's a leaky abstraction and so for this 它是一个漏洞百出的抽象,并且 因此,
reason we believe that learning get 出于这个 原因,我们认为从
5:37 topped down starting with the interface is 界面开始学习 可能不是最好的方法,它
maybe not the best way to go and it
5:42 can lead to some confusion it's possible 可能会导致一些混乱,可能会 像这部漫
like this comic shows to memorize a 画那样记住

about:blank 4/52
2023/5/11 15:40 For print

5:46 handful of commands and think of them 一些命令并将它们视为 魔法咒语, 为什


as magic incantations and why 么
everything's
5:50 working all right it kind of works out all 一切正常它有点 正常但是当出现问题时
right but then you have to follow 你必须遵循
5:54 the approach of this comic whenever 这个漫画的方法
things go wrong
5:57 so while git has an ugly interface its 所以虽然git有一个丑陋的界面它的 底层
underlying design and ideas are actually 设计和想法实际上
6:03 pretty beautiful an ugly interface has to 非常漂亮一个丑陋的界面 必须被记住 但
be memorized but the beautiful ideas 是
6:08 underlying git can actually be understood git 背后的美妙想法实际上是可以 理解
and once you understand gets 的,一旦你理解了
6:12 internals its data model which is actually 它的内部结构,它的数据模型 实际上并
not that complicated then you 不那么复杂,那么你
6:17 can learn the interface to get you you'll 可以学习界面来获得 你必须记住一些东
have to memorize some things but 西,但
6:20 you can understand what exactly certain 你可以理解某些命令到底是什么 通过了
commands do by understanding how 解它们如何
they
6:25 manipulate the underlying data model 操纵底层数据模型来做到这一点, 因此
and so the way we're going to teach get 我们今天要教授的方法
6:29 today is first talk about the data model 是首先 几乎抽象地谈论数据模型谈论我
almost in abstract talk about how we 们如何对
6:33 might model files and folders snapshots 文件和文件夹 的历史快照建模以及它们
of history and how they relate to each 如何与每个
6:37 other then after that we'll walk you 之后,我们将引导您完成
through
6:40 some get commands and then finally in 一些 get 命令,最后在 资源和练习中将
the resources and exercises will link
6:43 you to tutorials that'll teach you all the 您链接到教程,这些教程将教您所有 细
specifics because there are lots of 节,因为有许多
6:47 different commands that you will need to 不同的命令,您 最终需要学习任何问题
learn eventually any questions so far 到目前为止,
6:51 about our teaching approach for today 关于我们今天的教学方法 非常棒,让我
cool great so let's get started there 们开始吧,
6:59 are probably many ad hoc approaches 您 可能可以采用许多临时方法来进行版
you could take to version control and I'm 本控制,我
7:03 guessing some of you may have done 猜你们中的一些人之前可能已经这样做
this before like say you have some file or 过, 比如说您有一些文件或
7:07 folder we have a bunch of different files 文件夹我们有 一堆不同的 文件对应的系
corresponding system software 统软件
7:10 project and you want to track changes 项目,你想跟踪变化 你可以每天说复制
you could just say every day make a
about:blank 5/52
2023/5/11 15:40 For print

copy
7:14 of that entire folder and give that folder a 整个文件夹并给那个 文件夹一个时间戳
timestamp when you want to do 当你想做一些
7:17 things like collaborate with other people 事情比如与其他 人合作你可以拿走整个
you could take the entire folder 文件夹将
7:20 turned it into a zip archive and email it to 其转换为 zip 存档并将其通过电子邮件发
somebody and then whenever you and 送 给某人,然后每当您和
7:24 your buddy are working on two different 您的伙伴正在处理 软件项目的两个不同
features of a software project you can 功能时,您可以
7:27 work on them in parallel then one of you 并行处理它们,然后你们中的一个将 zip
emails the zip file to the other person 文件通过电子邮件发送给另一个人
7:30 and then you manually copy and paste ,然后 您手动将 他们代码中的适当部分
the appropriate segments from their code 复制并粘贴

7:34 into your code so that eventually you end 到您的代码中,这样最终您会 得到一段
up with one piece of code that has 代码,
7:38 both of your features in it this kind of sort 其中包含您的两个功能 如果您在我
of works raise your hand if you've
7:43 done this before I certainly have still a 之前这样做过,请举手 当然还有相当多
decent number 的
7:47 of you get let's us not do this sort of thing 人让我们不要做这种 事情
7:52 it is a well-thought-out model that kind of 这是一个经过深思熟虑的模型,可以 促
facilitates these sorts of 进这些类型的
7:56 interactions things that you might want to 交互你可能想做的事情 就像在你的项目
do like tracking your own history on 中跟踪你自己的历史
8:00 your in project or collaboration or things 或协作或 类似的事情,所以 git 有一个经
like that so git has a well 过
8:04 thought-out model that enables things 深思熟虑的模型,可以实现 分支和协作
like branches and collaboration and 以及
8:08 merging changes from other people all 合并来自其他人的更改等 各种整洁的东
sorts of neat stuff get models history 西获取模型历史记录
8:13 is a collection of files and folders within 是某个顶级目录中的文件和文件夹的集
some top-level directory so 合 所以
8:16 you're probably familiar with this 您可能 只是从自己计算机上的文件和文
abstraction just from files and folders 件夹中熟悉这种抽象,
8:19 on your own computer and so here's one 所以这是一个 示例,例如您可能有一些
example like you might have some
8:23 top-level directory I'll just call this like root 顶级目录,我将其称为 括号中的 root 并
in parentheses and this 且该
8:27 directory might have say a folder in it 目录可能会说一个文件夹在 它 叫做
called foo and this folder inside of it foo,它里面的这个文件夹
8:32 might have a file called bar dot txt and 可能有一个名为 bar dot txt 的文件, 里
this might have some contents in it like 面可能有一些内容,比如
about:blank 6/52
2023/5/11 15:40 For print

8:38 say this says hello world and then maybe this says hello world 然后也许 这个顶级
this top-level directory it has one 目录里面有一个
8:45 folder in it it caalso have another file in it 文件夹它也有另一个文件 在里面说还有
so say there's some other file 一些其他文件
8:49 and this file also has some contents in it ,这个文件也有一些内容, 很
all right
8:58 simple enough the terminology get uses 简单,术语得到用于 文件和文件夹的这
for these different things for files and 些不同的东西
9:03 folders is this and the top-level thing are 是这个,顶层的东西 叫做树,所以这是
called trees so this is a folder and 一个文件夹和
9:15 then these things what we normally call 然后这些我们通常 称为文件的东西称为
files are called blogs all right ok so 博客,好吧,
9:27 now we have a model of files and folders 现在我们有一个文件和文件夹模型, 这
and this is a recursive data structure 是一个递归数据结构
9:32 trees can contain other trees and then 树可以包含其他树然后 树可以包含树和
trees can contain both trees and files 文件
9:37 obviously files can't contain trees all right 显然文件不能 包含树 所以现在我们有一
so now we have a model of files 个文件
9:43 and folders and the kind of top-level of 和文件夹的模型以及 这个东西的顶层我
this thing the thing I've just labeled 刚刚标记为
9:49 root is the directory being tracked like 根的东西是被跟踪的目录就像 你的计算
you might have some folder on your 机上可能有一些文件夹
9:53 computer corresponding to a software 对应于一个软件 现在开始项目
project now how do you model history
9:58 once you have a model of files and 一旦你有了文件和 文件夹的模型,你如
folders well you can imagine one way of 何对历史建模 你可以想象一种方法,那
10:02 doing it which is you take a snapshot of 就是你拍摄 整个事物的快照,然后历史
this entire thing and then history is 只是快照的
10:05 just a linear sequence of snapshots like 线​​性序列,就像 你想象的那样 你
you might imagine that it's you can
10:10 almost think of it like you have copies of 几乎可以认为它就像你有 文件夹的副
the folder which are dated and 本,这些副本有日期和
10:13 time-stamped well it doesn't use a simple 时间戳,它没有使用 简单的线性模型,
linear model like that it uses 它使用了
10:18 something a little bit fancier you might 一些你可能 以前听过这个术语但
have heard this terminology before but
10:21 git uses a directed acyclic graph to model git 使用的更高级的东西 一个有向无环图
history and this might sound like 来 模拟历史,这听起来像是
10:25 a bunch of fancy math words but it's 一堆花哨的数学词,但 实际上并没有那
actually not all that complicated 么复杂,
10:29 so in get each snapshot has some 所以在获取每个快照时都有一定数量 的
number of parents and basically want to 父母,并且基本上想知道
know

about:blank 7/52
2023/5/11 15:40 For print

10:35 like what change preceded what other 什么变化先于其他 变化所以假设在这里


change so suppose here I'm going to use 我将使用

10:39 circles to refer to individual snapshots 圆圈来指代各个快照 这是这棵树中的全


this is the entire contents within this 部内容
10:44 tree so all the files and folders in my 所以我项目中的所有文件和文件夹 我的
project my entire project may be in some 整个项目可能处于某种
10:50 state and then I edit some files and now 状态然后我编辑一些文件现在 它处于另
it's in some other state and then I add 一种状态 然后我添加了
10:55 some more files and that's in some other 更多文件,这些文件处于其他 状态,每
state and every state points back to 个状态都指向
10:58 which state preceded it this so far is a 它之前的状态,到目前为止这是一个 线
linear history 性历史,
11:03 but it lets us do something a little bit 但它让我们可以做一些 比这更有趣的事
fancier than this you can also from a 情,你也可以从
11:08 certain snapshot fork your history and 某个快照分支 你的历史并 说我想基于这
say I want to base changes off of this 个
11:14 version and create a new snapshot like 版本的变化并创建一个像 这样的新快照
this so this way of modeling history 所以这种建模历史的方式
11:22 allows you to do things like okay I'm 允许你做这样的事情好吧我正在 做我的
working on my project this is my main 项目这是我的主要
11:25 line of development I go up to here and 开发线我走了 到这里, 现在我有两个不
now I have two different tasks I want to 同的任务要
11:29 work on suppose on one hand I have 处理假设一方面我有一些 奇特的新功能
some fancy new feature I want to add to 我想添加到我的
my
11:33 project and so I'm going to be working on 项目中所以我将 为此工作几天但
that for a couple days but separately
11:36 from that somebody's reported a bug to 与此分开 有人向我报告了一个错误, 我
me and I need to go chase down that bug 需要去追查那个错误
11:39 and fix it well instead of working on all 并很好地修复它,而不是 在
that stuff kind of concurrently at
11:43 the same time in the same line of 同一时间在同一条开发线上同时处理所
development 有这些东西
11:46 git has its way of branching the history git 有它的方式将历史 分为两个独立的部
into two separate Forks and working on 分 分叉并以一种彼此无关的方式暂时并
行处理
11:50 different things in parallel temporarily in a 不同的事情,
way that are unrelated to each
11:54 other so I could take this base snapshot 所以我可以拍摄这个基本快照, 就像我
like my project is in some state where 的项目处于某种
11:58 it works and then from here I could 工作状态一样,然后从这里我可以 实现
implement a new feature that creates a 一个创建

about:blank 8/52
2023/5/11 15:40 For print

12:03 new snapshot so this has the base 新快照的新功能 所以这有基础 项目加上
project plus a new feature so I'll do 一个新功能所以我会
12:07 like plus feature and then similarly 喜欢加功能然后类似地与 此分开我可以
separately from this I could go back to 回到
12:13 this original snapshot because I don't 这个原始快照因为我 不想在实现
want to do bug fixing while implementing
12:16 my new feature go here and then work 我的新功能时修复错误去这里和 然后处
on my bug fix and create a different 理 我的 bug 修复并创建一个不同的
12:20 snapshot so this has only the bug fix 快照,这样它只有 bug 修复
12:26 but not the feature and then finally once 但没有功能最后 一旦我并行完成了这两
I've done these two separate things 个独立的事情
12:30 in parallel eventually I want to incorporate 最终我想将 它们全部合并到我的公共
them all into my common
12:34 source code that has both the feature 源代码中 功能 和错误修复,所以最终我
and the bug fix so eventually I might 可能会
12:37 author a new snapshot by merging the 通过合并 这两个不同快照中存在的更改
changes present in these two different 来创建一个新快照
12:41 snapshots and so this one I'll have both ,所以这个我将把这两个 快照作为父快
of these snapshots as parents and this 照,
12:47 version here will have both the feature 这里的这个版本将同时具有功能 和我的
and my bug fix so does it make sense 错误修复 所以为什么以
why
12:58 get models history in a way that's a little 一种 比
bit fancier than just a sequence
13:02 of snapshots of my files and folders why I 我的文件和文件夹的一系列快照更有趣
want to be able to support branching 的方式获取模型历史是有意义的 为什么
我希望能够支持分支以
13:06 to work on things in parallel and then also 并行处理事物然后 合并到 合并来自开发
merging to combine changes from 问题的
13:10 different parallel branches of 不同并行分支的更改
development question
13:16 yeah so that's an excellent point it seems 是的,这是一个很好的观点 似乎当你合
that when you merge things you 并东西时你
13:22 could create errors that weren't 可能会产生意想不到的错误 你可以在这
anticipated you could imagine here that 里想象
13:25 this feature actually changes something 这个功能实际上改变了一些 使得这个错
that makes this bug-fix redundant or you 误修复冗余的东西或者你
13:29 could imagine this bug fix breaking this 可以想象这个 bug 修复破坏了这个 功能
feature or something like that oh that's 或类似的东西哦,这是
13:32 a really good point that's a something 一个非常好的点, 这就是所谓的合并冲
known as merge conflicts and this is 突,这是
13:36 something that git will try to do like when git 会尝试做的事情,就像 当你合并你的
you merge your parallel branches of 并行开发分支时,

about:blank 9/52
2023/5/11 15:40 For print

13:40 development it will try to automatically 它会尝试自动 合并 更改以


combine the changes in a way such that
13:44 it retains all the important changes but if 保留所有重要更改的方式进行,但是 如
it gets confused it will report a 果它感到困惑,它将报告
13:48 merge conflict and then leave it up to you 合并冲突,然后由 程序员决定如何将
the programmer to figure out how to
13:52 combine kind of concurrent changes to 并发更改组合到 相同文件或类似的东西
the same files or things like that and that and
13:56 then get has some tools for facilitating then get 有一些工具可以帮助解决 这个
this any other questions great ok so now 任何其他问题,很好,所以现在
14:05 we have a model files and folders and 我们有一个模型文件和文件夹, 然后我
then we have a model of history how 们有一个历史模型
14:09 different snapshots of our code relate to 我们的代码的不同快照如何相互关联
each other
14:11 one little detail here is that each of these 这里的一个小细节是每个 这些圆圈所以
circles so they kind of correspond 它们有点对应
14:17 to a snapshot like a tree with files and 于一个快照,就像一棵包含文件和 文件
folders but they also have a little bit 夹的树,但它们也有
14:22 of metadata so like inside here we might 一些元数据,所以在这里我们可能 有像
have like the author of this commit is 这个提交的作者是
14:29 me and we might have other metadata 我,我们可能有其他元数据,比如 一些
like some message associated with this 消息 与此提交相关联,
commit
14:36 I might describe what kinds of changes 我可能会描述 我所做的哪些更改存在于
I've made that are present in this 此
14:40 snapshot but not the previous one 快照中,但不是前一个
14:48 that is not really the chair class so next 不是真正的主席类的更改,所以 接下来
we're going to talk about kind of 我们将讨论比
15:01 one level lower than this like how exactly 这低一级的类型,例如 这究竟是如何表
is this represented as a as a 示为
15:07 data structure inside get and so I'm get 中的数据结构的,所以我 实际上要写
actually going to write down pseudocode 下伪代码,
15:10 because I think it's actually easiest to 因为我认为这种方式实际上最容易 理解
understand this way so first we have 所以首先我们有
15:15 files so a log is just a bunch of bytes so 文件,所以日志只是一堆字节 所以我 会
I'll say this is an array of bytes 说这是一个字节数组
15:26 okay then what is a tree remember that 好吧那么什么是树记住 这只是一个文件
this is just a folder of what are 夹,
15:34 folders they're mappings from the 它们是从 文件名或目录名映射到实际
filename or directoryname to the actual
15:41 contents and the contents are either 内容的文件夹,内容是 另一棵树,如子
another tree like a subtree or the file 树或 文件,

about:blank 10/52
2023/5/11 15:40 For print

15:50 and then finally we have the last thing 最后我们有了最后一件事,


there what I've been calling snapshots
15:57 so far and get terminology those are 到目前为止我一直称之为快照,并获得
called commits and so what does a 术语,这些被 称为提交,所以提交是什
commit

16:04 [Applause] it's a bunch of stuff commits [掌声] 这是一堆东西,提交有
have
16:09 parents that describes what precede 父级描述它们之前的内容 所以 在大多数
them so in the case of most normal 正常提交的情况下,
commits
16:16 they have one parent like what they 它们有一个父项,就像它们 来自什么合
came from what merge commits can 并提交可以有
have
16:19 multiple parents so parents are an array 多个父项,所以父项是一组 提交,然后
of commits and then I have some 我有一些元数据,
metadata
16:31 like the author and maybe a message 比如作者,可能还有一条消息
16:42 and then finally the actual contents the ,最后是实际内容 snapshot 这是一棵
snapshot which is a tree that's the 树,它是
16:50 top-level tree corresponding to a 对应于 特定承诺的顶级树,所以这是一
particular commitment so this is a 个
16:55 really clean simple model of history and 非常干净的简单历史模型, 这基本上就
this is basically all there is to how 是关于如何
17:00 get models history any questions about 获取模型历史的所有问题, 所以现在我
that all right so now we have that going 们开始了 更
17:10 a little bit deeper let's talk about how it 深入一点,让我们谈谈 它实际上是如何
actually stores and addresses this 存储和处理这些
17:15 actual data like at some point this 实际数据的,就像在某些时候这 实际上
actually has to turn to data on disk 必须转向磁盘上的数据一样,
17:18 right so get defines an object kind of a 所以 get 定义了一个对象,这是一个 长
big standing term but an object is any 期存在的术语,但对象是
17:28 one of those three things so it's a blob or 这三个中的任何一个 东西,所以它是一
a tree tree or a commit and then in 个 blob 或一棵树或一个提交,然后在
17:39 get all objects are content addressed so get 中所有对象都是内容寻址的, 所以
what get maintains on disk and you get 维护在磁盘上,
17:45 can actually we can look at this later is a 实际上我们稍后可以看到这 是一组维护
set of objects maintained as this 为这个
18:00 content address store so if you have any 内容地址存储的对象,所以如果 你有 这
one of these objects the way you put it 些对象中的任何一个,你把它
18:06 into this store is its key is the hash of the 放入这个商店的方式是它的键是 对象的
object so like in pseudocode I 哈希所以就像在伪代码中我
18:12 might say that to store a particular object 可能会说存储一个特定的 对象o我所做的
o what I do is I compute its ID 是我

about:blank 11/52
2023/5/11 15:40 For print

18:19 by taking the sha-1 hash of o and then I 通过获取sha来计算它的ID -1 hash of o


然后我
18:27 put it into my objects map store it to disk 把它放到我的对象中 map 将它存储到 磁
a quick show of hands who here 盘 快速举手 谁
18:36 knows what a hash function is all right so 知道什么是哈希函数 所以我会快速总结
I'll quickly summarize basically a 一下基本上是一个
18:42 hash function is you can think of it as like 哈希函数 你可以把它想象成 就像这个神
this magical function that takes a 奇的函数,它需要
18:45 big piece of data and turns it into a short 大量的数据并将它转换成 一个高层次的
string at a high level these are 短字符串,这些已经
18:51 used to or maybe that's like a sufficient 习惯了,或者这可能就像一个 足够的
18:55 clinician I won't go into too much more 临床医生,我不会 在这里详细介绍,但
detail here but you can ask me 你可以事后问我
18:58 afterwards if you're if you're curious so 如果你很好奇, 那么基本上他们会为你
basically they give you a way to name 提供一种命名
19:02 a thing in a way that's kind of 事物的方法,这种命名方式是一种 确定
deterministic based on the constants of 性的方式,基于
19:06 the thing it takes into thing as input and 它作为输入的事物的常量, 并给你一个
gives you a short name for it and 简短的名字,
19:09 then the opposite of stores load the way 然后 与商店加载相反的是 我们可以从商
we can load things from the store you 店加载东西的方式你
19:16 might have just guessed you can look 可能只是猜到了你可以 通过他们的 ID 来
them up by their ID and this is just we 查找它们,这只是我们
19:28 retrieve it from the object store by ID and 通过 ID 从对象存储中检索它 并且它会返
it gives us back the contents any 回内容给我们任何
19:36 questions about this so far question that's 问题 到目前为止,这是 一个很好的问
a good question what language is 题,它是用什么语言
19:42 it's all written in it's written in the 编写的,它是用 我刚刚编写的语言编写
language I just made up so it's 的,所以它是
19:45 pseudocode the get implementation itself 伪代码,get 实现本身 是 C 的混合,它
is a mix of C it's mostly C and then 主要是 C,然后是
19:51 some bash and Perl scripts I think any 一些 bash 和 Perl 脚本,我认为任何 其
other questions is this made-up language 他 问题是这种虚构的语言是否

19:57 clear enough or do I need to explain any 足够清晰,或者我是否需要解释 它的任


aspects of it great okay so blobs trees 何方面,好吧,所以 blob 树
20:06 and commits and get are unified in this 和提交和获取以这种 方式统一它们都是
way they're all objects and also as you 对象,而且正如你
20:14 might think given my description here like 可能认为的我在这里的描述 一样 看起来
it looks like commits contain a 提交包含
20:19 whole bunch of other commits and 一大堆其他提交并包含 快照和类似的东
contain a snapshot and things like that in 西在

about:blank 12/52
2023/5/11 15:40 For print

20:22 practice it doesn't actually work that way 实践中它实际上并没有那样工作 而是所


instead all these are pointers so a 有这些都是指针所以
20:28 commit will be able to reference a bunch 提交将能够 通过他们的 ID 引用一堆父母
of parents by their IDs so this is 所以这个
20:34 actually not an array of commits 实际上不是提交本身的数组, 而是 ID,
themselves but IDs and similarly the 类似地,
20:38 snapshot inside a commit is not the 提交中的快照不是 实际的树对象,它是
actual tree object it's the ID of the 树的 ID
20:42 tree and so all these objects are kind of ,因此所有这些对象都 存储在这个对象
stored on their own in this object
20:46 store and then all the references to 存储中,然后是所有引用 到 不同的对象
different objects are just by their ID 只是通过他们的
20:50 by their sha-1 hash does that make sha-1 散列的 ID 这是否有意义 你几乎可
sense you can almost in your head map 以在你的脑海中将它映射到
it to
20:55 like these are objects in a programming 就像这些是 像 Java 这样的编程语言中的
language like Java and then this is a 对象然后这是
21:00 reference to a tree so it's like a pointer 对树的引用所以它就像一个 指针 然后那
and then that is your realm 是你的领域
21:04 maybe this naughty helps maybe it 也许这个顽皮的帮助也许它 不是 是的 是
doesn't
21:08 yeah yeah exactly so I'll just repeat that 的所以我只是重复一遍 让每个人都听到
for everybody to hear on the
21:20 microphone this is gets on disk data store 麦克风 这是在磁盘数据存储上获取它是
it's a 一个
21:24 Content address store where objects are 内容地址存储,其中对象被 寻址 到目前
addressed by their hash all right any 为止,他们的散列没
21:36 questions about that so far ok so now we 问题,所以现在我们 有一种识别方法,
have a way of identifying we've unified 我们已经将
21:45 all the different types of objects into one 所有不同类型的对象统一为 一种我们称
type of thing we call object and we 为对象的东西,并且我们
21:50 have a way of identifying objects by their 有一种通过 sha-1 识别对象的方法 散列
sha-1 hash what do these actual 这些实际的
21:54 sha-1 hashes look like well they're sha-1 散列看起来像什么它们 是 40 个字
hexadecimal strings that are 40 符长的十六进制字符串,
21:58 characters long like sha-1 is a 160-bit 就像 sha-1 是 160 位散列,因此
hash and so one
22:02 of the actual IDs returned by that sha-1 该 sha-1 函数返回的实际 ID 之一 将是
function is going to be a really long 一个很长的
22:07 string and so given that we'll have ways 字符串,所以如果我们有办法
of identifying these different things
22:13 like this we'll have corresponding to it an 像这样识别这些不同的东西,我们就会
ID like for a 3-2 CEB or something 有 一个与之对应的 ID,比如 3-2 CEB 之

about:blank 13/52
2023/5/11 15:40 For print

22:20 something so now we have a way of 类的东西,所以现在我们有办法命名 这


naming everything in this commit graph 个中的所有东西 commit graph 但
but
22:29 these names are really inconvenient 这些名称真的很不方便, 因为它们超长
because they're super long and they're 而且它们
22:33 like text strings they're not meaningful to 就像文本字符串,它们 对人类没有任何
humans in any way so it's solution to 意义,所以解决
22:38 this problem is one other thing so get 这个问题是另一回事,所以 get 维护一组
maintains a set of objects and then it 对象然后 它
22:43 maintains a set of references what our 维护了一组 引用我们在这里的引用我会
references here I'll erase this bit on 在左边擦掉这部分
22:48 the left this parts pretty logical 这部分很合乎逻辑
22:54 that's the irony another time so 那是另一次具有讽刺意味的是所以 引用
references all right here 在这里都是正确的
23:03 so this is another piece of data that get 所以这是另一段数据 在内部维护引用是
maintains internally references is a
23:08 map from string to string and you can 来自字符串的映射 到字符串,您可以 将
think of this as mapping human readable 其视为映射人类可读的
23:18 names like I might have a name like fix 名称,例如我可能有一个名称,例如 fix
encoding bug fix - encoding - bug is a encoding bug fix - encoding - bug is a
23:28 human readable name and this would be human readable name and this would
maps to like that long hexadecimal be maps to like that long hexadecimal
23:33 string there and so with these references string there and so with these
and you can imagine how we references 你可以想象我们
23:38 might have ways of creating new 如何创建新 引用和更新引用以及
references and updating references and
23:43 things like that with this I can now refer to 类似的东西 我现在可以
things in
23:48 my commit graph by name so I might 通过名称引用我的提交图中的东西所以
have the same be called like fix bug or I 我可能会 像修复错误一样调用它或者我
23:55 might have a name for something over 可能有一个 这里的东西的名字是 这样
here things like that and so yeah with 的,所以是的,
24:00 this skit can use human readable names 这个小品可以使用人类可读的名称 来指
to refer to particular snapshots in the 代历史中的特定快照,
24:04 history instead of these long hexadecimal 而不是这些长的 十六进制字符串,这里
strings one other thing to 要注意的另一件事
24:10 be aware of here is given gits design for 是 gits design for history this entire
history this entire graph is graph
24:16 actually immutable you can add new stuff 实际上是不可变的你可以向它添加新的
to it but you can't actually manipulate 东西 但你不能
24:20 anything in here I won't go into the details 在这里实际操作任何东西我不会 详细说
of exactly how or why but just 明如何或为什么但只是假设

about:blank 14/52
2023/5/11 15:40 For print

24:25 assume that that's the case however 情况就是这样但是引用是不可变的所以


references are immutable so as you're 你正在
24:30 updating the history like suppose you 更新 历史就像假设你 继续在这个软件上
keep working on this piece of software 工作
24:32 you create a new commit so I'm 你创建了一个新的提交所以我 用圆圈表
representing that by the circle this 示这个指向
24:36 points to the previous commit I can 上一个提交我 实际上可以说我的固定错
actually have say my fixed bug reference 误参考
24:40 is pointing here I can update this 指向这里我可以更新这个 参考到 现在指
reference to now point over here 向这里但是
however
24:48 I can't for example make this point over 我不能例如在这里提出这一点 这甚至不
here that's not even a meaningful thing 是有意义的事情
24:52 to say because this is just the hash of 因为这只是 这个对象的散列来改变这个
this object to change this hash I'd need 散列我需要
24:57 to change the contents of the object 改变对象的内容 它不 到目前为止,
which doesn't really make sense
25:02 all right any questions about that so far 关于它的任何问题都没有任何意义, 基
that's basically it forgets data 本上它忘记了数据
25:06 model and then we'll go into actually 模型,然后我们将 通过命令行与 get 进
interacting with get via the command 行实际交互
25:10 line and we'll see how git commands ,我们将看到 git 命令如何 与图形数据结
correspond with manipulations of a graph 构的操作相对应
25:14 data structure so any questions about 所以关于将 历史建模为树和
modeling history as trees of trees and
25:21 blobs and then snapshots these things blob 的任何问题然后快照这些 称为提交
called commits being chained together 的东西被链接在一起
25:25 and you have references that can point to 并且你有可以 指向该图中特定节点的引
particular nodes in this graph cool 用很酷
25:32 no questions so basically once we have 没有问题所以基本上一旦我们有 对象和
objects and references like that's 引用基本上就是
25:41 basically all there is to a git repository 全部 有一个 git 存储库,它们是
those are the two pieces of
25:46 data that it stores and at a high level 它存储的两部分数据,在高层次上,
25:53 all get command line commands are just 所有 get 命令行命令都只是 对引用
manipulations of either the references
25:59 data or the objects data okay so for the 数据或对象数据的操作,好吧,在 本节
rest of this lecture I'm going to go 课的其余部分,我将继续
26:12 through some git commands it's basically 通过一些 git 命令,它基本上 将是一个类
going to be an interactive demo similar 似于
26:16 to the vim lecture and then you can refer vim 讲座的交互式演示,然后您可以 参
to the notes for full information 考注释以获取有关

about:blank 15/52
2023/5/11 15:40 For print

26:19 on these commands look of course it's a 这些命令的完整信息当然,它是一个 非


really powerful tool we can't cover 常强大的工具,我们无法涵盖
26:23 everything in what 20 minutes all right so 所有​​内容 20 分钟好吧, 所以我要转到这
I'm going to go over to this folder 个
26:29 called playground and I'm going to make 名为 playground 的文件夹,我将 在
a new directory called demo CD into demo 中创建一个名为 demo CD 的新目
demo

26:33 and this directory is going to represent ,这个目录将代表 我项目的顶层,它
the top level of my project it's
26:37 currently empty because I just created it 目前是空的,因为我只是 创建 它,如果
if I want to turn this into a git 我想把它变成一个 git
26:44 repository I use the git init command get 存储库,我使用 git init 命令 获取它代表
in it stands for git initialize and git 初始化,
26:49 we see that it says initialized empty git 我们看到它 在 blah blah slash dot git 中
repository in blah blah slash dot 说 initialized empty git repository
26:54 git if I do LS I still see nothing but if I do if I do LS 我仍然什么都看不到,但 如果
LS - a there's a hidden file in 我执行 LS - 如果
27:01 this directory called dot git if I do LS get 我执行 LS,此目录中有一个名为 dot git
there's a bunch of stuff in here 的隐藏文件, 这里有一堆东西
27:05 this is the directory on disk where it gets 这是磁盘上的目录,它 存储所有内部数
stores all of its internal data 据,
27:09 namely the objects and the references 即对象和引用 以及 你实际上在这里看到
and you actually see here objects and 对象和
27:12 refs as two directories in here and all the refs 作为两个目录, 所有存储库数据将
repository data will be stored 存储
27:17 underneath those two directories one 在这两个目录下一个 字母命令要记住,
letter command to keep in mind as we're 因为我们
27:23 going through these is something called 正在经历这些是称为 get help get help 的
get help get help takes a sub command 子命令作为
as
27:27 an argument it gives you some help on it 一个参数它给你一些帮助 所以如果我确
so if I do get help in it for example 实得到帮助例如
27:30 it'll tell me about the git init command so 它会告诉我关于 git init 命令 所以现在有
now there are some commands for 一些命令可以
27:37 figuring out what's going on with a git 弄清楚 git 存储库发生了什么, 比如 git
repository like git status at a high status 在 高层
27:41 level says what is going on right now and 说现在发生了什么, 我们在这里看到让
we see here let's ignore the first 我们暂时忽略第一
27:45 line for now the second line says no 行第二行说 还没有提交那是因为我们刚
commits yet that's because we just 刚
27:49 initialized a fresh repository and so there 初始化了一个新的存储库所以 没有历史
is no history yet I'm actually 但我实际上

about:blank 16/52
2023/5/11 15:40 For print

27:53 going to does anybody still want this are 会做任何人 仍然希望 这部分很清楚,
kind of clear this part of the board
27:59 I'm going to as we go along draw how the 我将继续绘制当我输入某些 git 命令时 底
underlying objects and references data 层对象和引用数据
28:05 is changing when I type in certain git 是如何变化的, 所以现在这张图片或
commands so right now this picture or
28:10 lack of picture represents the current 缺少图片代表当前 我们存储库的状态它
state of our repository it's empty there 是空的
28:13 are no snapshots so let's fix that let's add 没有快照所以让我们修复一下让我们 在
something to our history here we 这里添加一些东西到我们的历史我们
28:19 have no files so let me just go ahead and 没有文件所以让我继续 创建一个文件
create a file hello.txt with the hello.txt 与
28:25 content hello world normally you'd have 内容 hello world 通常你会有 你的源 代码
your source code with actually useful 中包含实际有用的
28:28 stuff in it now what I want to do is I want 东西现在我想做的是我 想获取此目录的
to take the current contents of 当前内容
28:33 this directory and turn it into a new 并将其转换为新 快照以表示
snapshot to represent say the first
28:37 state my project was in you might 我的项目所处的第一个状态你可能会 想
imagine an interface for doing this 象一个用于执行此操作的界面
28:42 where there is like a git snapshot 有一个 git snapshot 命令或 get
command or get something else something else 命令,
command
28:46 which takes a snapshot of the entire state 它拍摄 当前目录的整个状态的快照出于
of the current directory for a
28:50 number of reasons git doesn't have a 多种原因,git 没有一个 完全像那样工作
command that works exactly like that 的命令,
28:52 because git wants to give you a little bit 因为 git 想给你一点点 关于在
of flexibility as to what changes to
28:57 include in the next snapshot you take this 您拍摄的下一个快照中包含哪些更改的
is something that's kind of 灵活性, 这
29:00 confusing to beginners sometimes so I'll 有时会让初学者感到困惑,所以我 现在
try to explain it right now git has a 将尝试解释它 git 有一个
29:04 concept of something called a staging 叫做暂存区的概念, 在高层次上它是
area and at a high level it's where you
29:10 tell git what changes should be included 如果我们在这里获得状态,你告诉 git 下
in the next snapshot you take if we do 一个快照中应该包含哪些更改,
29:15 get status here we'll see that git says no 我们会看到 git 说 没有提交,就像它之前
commits yet like it said before and 说的那样,
29:19 it says untracked files hello Tex so this is 它说未跟踪的文件 hello Tex 所以这是说
saying that get notices that 得到通知
29:25 there's a new file in the current directory 当前目录中有一个新文件, 但它不会
but it is not going to be

about:blank 17/52
2023/5/11 15:40 For print

29:28 included in the neck snapshot gets kind 包含在颈部 快照中,现在有点忽略它,


of ignoring it for
29:30 now but if I do get ad hello text and if I do 但如果我确实收到广告问候文本,如果
get status again it says now 我再次获得状态,它会说现在
29:37 changes to be committed new file 要提交新的更改 文件 hello.txt 所以现在
hello.txt and so now if I do the get 如果我执行 get
29:42 snapshot command which is actually get snapshot 命令这实际上是 get commit 创
commit which creates a new one of those 建一个新的那些

29:46 circles I drone the board over there this 圈子我在董事会那边无人机 这个文件将
file will be included in that 包含在那个
29:50 snapshot I'm I take so let me go ahead 快照中我接受所以让我走 ahead 并运行
and run git commit what this does is it git commit 它的作用是
29:55 pops up my text editor and it lets me type 弹出我的文本编辑器,它让我 输入一条
in a message that will be
29:58 associated with this commit and it's really 与此提交相关联的消息, 编写高质量的
good to write high-quality commit 提交
30:02 messages because then later when 消息真的很好,因为稍后当你 回头看时
you're looking back at your products 在你的产品版本
version
30:05 history you'll know why you made certain 历史中,你会知道为什么你做了某些 改
changes I'm going to add this relatively 变 已经
30:12 useless commit message but we have a -
link in the lecture notes for a guide on
30:16 how to write high-quality commit 完成
messages so now that I've done that get
30:21 prints out some output master ignore that 打印出一些输出主机忽略 那个位现在这
bit for now this thing is the hash 个东西是
30:27 of the commit I just created so now I 我刚刚创建的提交的哈希所以现在我 在
have in my history a single node this 我的历史中有一个节点它
30:32 has in it a tree that has a single blob a 有一个树有一个单一的 blob 单一文件
single file hello.txt with the hello.txt
30:37 contents hello world and then this has the 内容是 hello world 然后它有 2fb 的 sha-
sha-1 hash for 2fb 1 散列
30:46 something something something it's 一些东西它 实际上在 get 接口中被截断
actually truncated in the get interface 了
30:49 as well this is just printing out my commit 这只是再次打印出我的 提交消息 它说作
message again and it says as a 为
30:55 reminder I just added hello dot text and 提醒我刚刚添加了 hello 点文本, 所以现
so now if I use the git log command so 在如果我使用 git log 命令,那么
31:00 the git log commit is really useful in that it git log commit 非常有用, 因为它可以帮
helps you visualize the history 助您可视化
31:04 the the commit graph if I do question 提交图的历史,如果我确实提出问题,

about:blank 18/52
2023/5/11 15:40 For print

31:16 that's a great question so the question is 这是一个很好的问题,所以问题 是这个


what exactly does this hash 哈希值到底
31:20 correspond to so this is the hash of the 对应什么 所以这是提交的哈希, 提交包
commit the commit contains inside of it 含
31:26 the hash of the tree along with whatever 树的哈希以及任何 其他信息,所以我可
other information so I can actually use 以实际使用
31:31 get cat file - P this number this is kind of 获取 cat 文件 - P 这个数字 有点像一个
like a get internals command get internals 命令,
31:38 that will print out the contents of this 它将打印出来 这个 提交的内容所以你可
commit so you can see this kind of maps 以看到
31:42 to data structure I drew on the board over 我在那边的板上画的这种数据结构的映

31:43 there so this commit has inside of it this 所以这个提交里面有 这棵树然后我是作
tree and then I'm the author and 者
31:48 this is the commit message and so on 这是提交消息等等 我 可以在这里继续挖
and I can continue digging down here so 掘,这样你
you
31:51 can take this hash of this tree and do get 就可以获取这棵树的哈希值并 获取 cat
cat file - P this hash here it says 文件 - P 这里的哈希值表示
31:56 that this tree has inside of it a single entry 这棵树内部有一个单独的 条目 hello 文
hello text and that file has it's 本,该文件是
32:02 a blob and it has this hash I can do get 一个 blob,它有这个哈希值 我可以获取
cat file - P this thing and it will show cat 文件 - P 这个东西,它会向
32:09 me the actual contents of that file so 我显示该文件的实际内容,所以 这些就
these are like internal git commands to 像内部 git 命令一样,用于
32:13 explore objects in the object store 探索对象存储中的对象 问题,这是一个
question that's a great question so the 很好的问题,所以
32:22 question is why did I have to use get add 问题是为什么我必须使用 get add 为什么
why can't you just commit all 你不能只提交所有
32:26 changes and the answer is well there 更改,答案很好
kind of is a way to commit all changes
32:30 if you do get commit - a this commits all 如果你确实提交了,有一种方法可以提
the changes that were made to files 交所有更改 - 这会提交 对已被 git 跟踪的
文件所做的所有更改
32:36 that are already being tracked by git so 所以 任何包含在
anything that was included in the
32:39 previous snapshot but has been modified 上一个快照中但从那时起被修改的东西
since then it doesn't include new things 它不包括新东西
32:43 there's also variants of git add like if you 还有 git add 的变体就像如果 你确实得到
do get add colon slash this will add 添加冒号斜杠这将添加
32:48 everything in the top from the top level 顶部的所有内容从 你的顶层向下 存储
down of your repository but at a higher 库,但在更高

about:blank 19/52
2023/5/11 15:40 For print

32:52 level the reason we have this separation 层次上,我们在 git add 和 git commit 之
between git add and git commit and why 间进行这种分离的原因以及为什么
32:57 get come it doesn't just snapshot the 它不只是快照 整个目录是因为它们通常
entire directory is that they're often 是
33:00 situations where you don't want to 您不想 包含当前目录中的所有内容的情
include everything in the current 况
33:03 snapshot like here's a couple examples 快照就像这里有几个例子, 一个是我可
one is that I might be packing on my 能正在打包我的
33:08 project and I go ahead and implement 项目,然后我继续实施两个 功能,也许
two features maybe I don't want to have 我不想在
a
33:11 single snapshot that comes after this one 这个快照之后出现一个快照, 就像我实
that's like I implemented feature a 现了功能 a
33:15 and feature B maybe I want to create two 和功能 B 也许 我想 在历史记录中创建两
separate nodes in the history so that it 个单独的节点,这样
33:19 looks like first I implemented feature a 看起来我首先实现了功能 a, 然后我实
and then after that I implemented 现了
33:22 feature B so I have one snapshot that 功能 B,所以我有一个快照 只包含 a,
only includes a and then the next one 然后下一个
33:25 includes both a and B git add is a tool 包含 a 和 B git add is 一个工具 ,就像一
and like the staging area in general is 般的暂存区一样,是
33:30 a tool that will allow me to do that sort of 一个可以让我做那种 事情的工具
thing
33:33 another example is suppose I'm working 另一个例子是假设我正在 修复错误并且
on a bug fix and I have printf 我有 printf
33:37 statements I've put all over my code and 语句我已经把所有的代码都放在了 最后
then finally I find the bug and there's 我发现了这个错误,并且在
33:40 a plus one somewhere where there 不应该有加号的地方有一个加号,所以
shouldn't be a plus one so go fix that 去修复它
33:43 and then I want to take a new snapshot 然后我想用我的修复拍摄一个新的快
right with my fix 照,
33:46 but the snapshot probably should include 但快照可能应该包括 它只需要的我的所
all of my print statements it just needs 有打印语句
33:50 to include the fix of removing that plus 包括删除那个加 一个的修复,所以我可
one so one way I could solve that issue 以解决这个问题的一种方法
33:53 is I can go in annually remove all the print 是我可以 每年删除所有打印语句,
statements
33:56 but it has a much better way of doing that 但它有更好的方法来做到这一点 实际上
there's actually a way to specify 有一种方法可以指定
34:00 that I only want to add the change of 我只想添加 删除那个加一的更改然后我
removing that plus one then I can commit 可以
34:05 that take the new snapshot and then I 提交拍摄新快照然后我 可以扔掉所有其
can throw away all the other changes
about:blank 20/52
2023/5/11 15:40 For print

他更改
34:09 there are commands for doing that and 有执行此操作的命令并且 其中一些在讲
some of them are linked in the lecture 义中链接
34:11 notes so those are two ways in which you 因此这是您的两种方式 可以使用暂存区
can use the staging area to help you and 来帮助你,

34:15 why there isn't just like a snapshot 为什么没有像快照一样的 一切命令是的


everything command yeah so mm-hmm 所以嗯嗯是的
yeah
34:24 John John points out the yeah yet 约翰约翰指出是的 另一个例子是你
another example is you might have log
34:27 files in your current directory that your 的当前目录中可能有日志文件, 你的程
program runs when you run it and 序运行时 你运行它并且
34:31 you probably don't want to include those 你可能不想 在拍摄快照时包含那些
when you take a snapshot there's
34:34 probably other things like if you compile 可能还有其他事情,比如如果你 编译你
your project you end up with a 的项目你最终会得到
34:37 bunch of dotto and like elf files you 一堆点和像精灵文件一样你 可能不希望
probably don't want those to be part of 它们成为一部分
34:40 your history so going back to what I was 你的历史所以回到我在 清除终端屏幕之
showing you before I'm going to clear 前向你展示的内容,
34:50 the terminal screen and then show you 然后向你展示 git log 命令所以记录让
the git log command so get logged lets
34:53 you visualize the version history and this 你可视化版本历史,
is an incredibly helpful command by
34:58 default git log shows you a flattened 默认情况下这是一个非常有用的命令 git
version of the version history so even log 向您显示 版本历史的扁平化版本,因

35:02 though the version history is a graph this 即使版本历史是一个图表, 这也会将其
will linearize it and just show 线性化并按顺序显示内容
35:05 things in order i personally find that -
confusing so I almost never use git log
35:08 and instead get log takes some 历史作为
arguments that actually show the history
as a
35:12 graph so you can treat this as a magic 图表,所以你现在可以把它当作一个魔
incantation for now and you can read the 法 咒语,
35:20 documentation if you want to figure out 如果你想 确切地弄清楚每个标志的作
exactly what each of those flags does 用,你可以阅读文档,
35:23 but for now this doesn't look all that 但现在看起来并没有什么 不同,因为我
different because we only have one node 们只有
35:27 in our graph so visualizing it as a 我们图表中的一个节点因此将其可视化
flattened thing versus a graph doesn't 为 扁平化的东西与图表
35:30 look all that different let me go ahead and 看起来并没有什么不同让我继续 创建一
create a new snapshot and then we 个新的快照然后我们
about:blank 21/52
2023/5/11 15:40 For print

35:36 can run this command again and then 可以再次运行这个命令然后看看 它到底
see exactly what it does so I will put 做了什么所以我会把
35:44 another line into hello dot text and so if I 另一行进入 hello dot 文本,所以 如果我
cat hello dot text it has the thing cat hello dot text 它
35:50 it had before plus this I can do get 有它之前的东西加上这个我可以得到 提
commit and notice this doesn't do 交并注意到它没有做
35:55 anything it just says no stained state no 任何事情它只是说没有染色状态 没有为
changes staged for commit why is that 提交准备的更改为什么是这样
36:00 it's because I didn't add this to the 这是因为我没有将它添加到 我还没有告
staging area I didn't tell yet but like 诉的暂存区,但就像
36:03 this is something that should be included 这是应该 包含在下一个快照中的东西
in the next snap
36:06 so if I do get ad hallo text get status it 所以如果我确实收到广告 hallo text get
says okay this change is ready to be status 它说好的这个更改已经准备好
36:13 committed this modification to this file 将此修改提交到此文件 ,现在我可以执
and now I can do git commit I'm gonna 行 git commit 我要
36:20 put in a useless commit message and the 放入一条无用的提交消息,并且已经 进
new changes have been made and so 行了新的更改,所以现在我的
now my
36:26 history has another note in it and then 历史记录中有另一个注释,然后 这个注
this note has some hash that's shown on 释有一些哈希值显示在
36:31 the screen and now if I rerun that 屏幕,现在如果我使用所有这些参数 从
command from earlier the git log with 之前的 git log 重新运行该命令,
36:37 all these arguments it actually starts 它实际上开始 看起来更像一个图表,请
looking more like a graph here notice 注意
36:41 that this is like that graph turned this way ,这就像该图表 最近以这种方式转动,
the more recent so it's shown 因此它显示为
36:47 vertically not horizontally and the more 垂直而不是水平,而 最近 提交显示在顶
recent commits are shown at the top this 部这
36:54 is showing one commit it shows as 显示了一个提交它显示为提交 哈希显示
commit hash shows a bunch of metadata 了一堆元数据包括
including
36:58 the commit message and then this is the 提交消息然后这是 我接下来要讨论的部
part I want to talk about next so 分所以
37:02 remember we talked about objects like 请记住我们讨论了诸如 存储库的实际内
the actual contents of your repository 容之类的对象
37:06 and then we talked about references 然后我们讨论了使用人类可读名称命名
ways of naming things in the repository 存储库中事物的引用方式,
with
37:10 human readable names so master is one 因此 master 是 在您初始化它时默认创建
reference that's created by default when 的一个引用
37:16 you initialize it get repository and by get repository 并且按照 惯例,它通常指
convention it generally refers to like 的是

about:blank 22/52
2023/5/11 15:40 For print

37:20 the main branch of development in your 代码中的主要开发分支所以 master 将代


code so master will represent like the 表
37:24 most up-to-date version of your project 项目的最新版本, 因此在这里您可以将
so here you can think of master as a master 视为
37:29 pointer to this commit and as we add 指向此提交的指针,并且随着我们添加
more commits this pointer will be 更多提交,此指针将发生
37:33 mutated to point to later commits then we 变化以指向以后的提交然后 我们也在这
also see here head this is a special 里看到 head this 是一个特殊的
37:39 reference and get it's a reference like 参考,它是一个像 master 一样的参考,
master but it's special in some way and 但它在某种程度上是特殊的,
37:42 head basically is used to refer to where head 基本上是用来指代 你目前正在寻找
you are currently looking right now any 的任何
37:49 questions so far yeah question 问题到目前为止,是的,
38:03 that's an excellent question so the 这是一个很好的问题,所以这个 问题之
question is work with github before and 前与 github 一起工作
38:09 you have to create an account to do that 你必须创建一个帐户才能做到这一点
how does github relate to get and the github 与 get 有什么关系,
38:13 answer to that question is github is a 这个问题的答案是 github 是 get 的存储
repository host for get so you can 库主机所以你可以
38:20 create an account on github and store a 在 github 上创建一个帐户并 在那里存储
git repository there and use that to 一个 git 存储库并使用它
38:24 collaborate with other people but git as a 与 其他人,但 git 作为 命令行工具只是
command-line tool is just independent 独立
38:27 from github so you don't have to use 于 github,所以你不必使用 github 来使
github to use git you don't have to use 用 git 你不必使用
38:31 github declare it with get either like there github 声明它与 get 一样,就像 有其他
are other providers of git git
38:34 repositories like bitbucket or get lab or 存储库提供者一样 bitbucket 或获得实验
things like that and so yeah github 室 或类似的东西所以是的 github
38:38 is a host for github repositories any other 是 github 存储库的主机任何 其他问题是
questions yeah so the question is 的所以问题是
39:04 if you want this repository to end up on 如果你希望这个存储库最终在 github 上
github how do you do that yeah there's a 你怎么做是的有一组
39:09 separate set of commands for doing that 单独的命令来做那个 有一个这样的概
there's a so that concept of having your 念,让你的
39:13 local copy of version history interact with 版本历史的本地副本 与另一个副本交
another copy so the other copy is 互,所以另一个副本被
39:17 called a remote and then their set of 称为远程,然后他们的 命令集用于与 git
commands for interacting with git
39:20 remotes and sending data from your 远程交互并从你的 远程或从你的副本发
remote or from your copy to get remotes 送数据以获取远程

about:blank 23/52
2023/5/11 15:40 For print

39:24 and getting data from git remotes into 和 从 git remotes 获取数据到 你的本地
your local copy and we'll cover that 副本,我们将
39:28 later in this lecture or maybe in the 在本课稍后部分或可能在 讲义中介绍
lecture notes Ron might make a Ron 可能会制作一个
39:31 supplemental video to go along with this 补充视频来配合 本课任何其他问题好
lecture any other questions okay a 吧,
39:39 couple other basic commands to show 其他一些基本命令可以向你展示 到目前
you so so far I've shown you a version 为止,我已经向您展示了版本
39:44 history and we've taken a file and 历史记录,我们已经获取了一个文件并
modified it but we haven't really made 对其进行了修改,但是除了阅读消息之
外,我们还没有真正以
39:49 use of the history in any way besides 任何方式利用历史记录, 所以一个有用
reading the messages so one useful git 的 git
39:53 command is something called git 命令是 git checkout 和这个 是一种古怪
checkout and this is a kind of wacky 的命令,它
command it
39:56 lets you do a bunch of different things but 可以让你做很多不同的事情, 但它可以
one thing it lets you do is move 让你做的一件事是
39:59 around in your version history so one 在你的版本历史中四处移动,所以 我能
thing I can do is give get checkout the 做的一件事就是给 get checkout 上
40:03 commit hash of a previous commit and I 一次提交的提交哈希,我 不这样做 不需
don't need to type the whole thing I can 要键入整个内容我可以
40:06 give it a prefix and it's to figure out what 给它一个前缀,它是 为了弄清楚我在说
I'm talking about and 什么,
40:09 what this will do is it will change the state 这将做什么,它将 我的工作目录的状态
of my working directory to how it 更改为
40:14 was at that commit so here if I do cat 提交时的状态,所以如果我在这里 do
hello text recall that I had only one cat hello text 记得我在
40:20 line in here before at the first commit and 第一次提交之前在这里只有一行 ,后来
later I added that second line now 我现在添加了第二行,
40:26 if I do that get logged command and this 如果我这样做了 get logged command 并
command is super helpful like it shows 且这个 命令非常有用,
40:29 you all the things if I do this command 如果我这样做它会告诉你所有的事情 命
notice that this output looks a little 令 注意,这个输出看起来与
40:33 bit different than before like my actual 以前有点不同,就像我的实际 历史内容
history contents the commits themselves 一样,它们
40:38 in the way they relate to each other and 以彼此相关的方式提交自己, 所有这些
all that have not changed but the 都没有改变,但
40:42 references have so notice that head is 引用已经注意到, 即使 master 仍然在,
down here even the master is still up head 在这里 在
40:46 here so at high level what this is telling 这里,所以在高层次上,这 告诉我这就
me is this is what I'm looking 是我现在正在看的东西,

about:blank 24/52
2023/5/11 15:40 For print

40:50 at right now if I want to go back here I 如果我想回到这里,我 可以输入 git


could type git checkout and this commit checkout 并且这个提交
40:56 hash does anybody know a different 哈希 是否有人知道我
thing I
40:58 could type here instead of this long hash 可以在这里输入不同的东西而不是 这个
in order to go back to this commit 长 散列是为了回到这个提交是
41:02 yeah you can give it the name of this is a 的,你可以给它起这个名字这是 一个绿
branch colored in green here and it 色的分支这里它
41:08 refers to this commit so I can give it the 指的是这个提交所以我可以给它 一个短
short name or the human readable 名称或人类可读的
41:11 name instead and now if I do cat hello 名称,现在如果 我做 cat hello text
text notice that it has that second line notice that it has the second line
41:22 [Music] [Music]
41:30 yeah yeah so to repeat that git checkout yeah yeah 所以重复 git checkout 实际上
actually changes the contents of your 改变了你的
41:43 working directory and so in that way it 工作目录的内容,所以 如果你滥用它,
can be a somewhat dangerous command 它可能是一个有点危险的命令,
if
41:47 you misuse it for example you can see if I 例如你 可以查看 我是否修改了 hello 文
modify hello text and then try that 本,然后尝试使用
41:54 get checkout command from earlier 之前的 get checkout 命令 实际上注意到
actually notice here that it says error 这里它说错误它
41:58 it says there's a file that's been modified 说有一个文件已被 修改并且 git checkout
and the git checkout would 会
42:02 destroy your modification you probably 破坏你的修改你可能 想做一些事情但是
want to do something about that but
42:05 there are flags like for example get 有 诸如 get checkout 之类的标志 - eff 强
checkout - eff does this forcibly and 制执行此操作,
42:09 now it's throwing away my changes so 现在它正在丢弃我的更改,所以 是的 get
yeah get checkout has the potential to checkout 有可能很好地
42:12 well it certainly does modify things in your 完成它确实会修改 您的工作目录中的内
working directory and it can 容,
42:15 actually destroy changes if you're not 如果您不 小心提问,它
careful question
42:23 exactly yeah this is exactly what I want 实际上可以破坏更改 是的,这正是我想
you to be thinking about how these like 让 你思考的,这些像
42:29 the crazy get interface commands 疯狂的 get 接口命令是如何 对应于这张
correspond to mutations to this graph 图的突变
42:33 and mutations to the reference or like 和参考的突变,或者像
additions to the graph in mutations to
42:37 the references map so yeah exactly get 参考图的突变中的图的添加,所以是
checkout moves the head pointer and 的,正是 get checkout 移动了 head
pointer

about:blank 25/52
2023/5/11 15:40 For print

42:43 then also mutates the contents of your 然后也用 head pointer 现在指向的内容
working directory with the contents that 改变你的 工作目录的内容
42:47 the head pointer now points to of course 当然 我的名字提交任何其他
my name for that commit any other
42:54 questions all right so one other basic 问题好吧所以 我想告诉你的另一个基本
command I want to show you is the git 命令是 git
43:03 diff command so I'm going to modify this diff 命令所以 我将修改这个 文件并在其
file and put some changes in it the git 中进行一些更改 git
43:08 diff command can show you what's diff 命令可以向您显示 自上次快照以来发
changed since the last snapshot it's just 生的更改 它只是
43:13 helpful for like knowing what's going on 有助于了解 您的项目正在发生的事情 git
with your project git diff can also take diff 也可以
43:18 extra arguments like you can do git diff 像您一样使用额外的参数 git diff 并说计
and say compute a diff not with respect 算差异不是
43:25 to the last snapshot the last commit but 关于最后一次提交的最后一个快照而是
with respect to this and say ok two 关于这个并且说好的两
43:30 lines have been added since this point to 行已经添加了因为这 指向你好点文本
hello dot text
43:40 question so your the question is what 问题所以你的问题是 这个命令没有这个
does this command do without this extra 做什么
43:52 argument here that's a good question so 这里的额外参数这是一个很好的问题,
what this does is it computes a DIF with 所以 它的作用是计算一个
43:59 respect to head and looking at my get log 关于 head 的 DIF 并查看我的 get log hat
hat is pointing to here so it's 指向这里所以它
44:07 doing a get diff with respect to this 正在做一个关于这个提交的 get diff 你实
commit and you can actually specify that 际上可以
44:10 explicitly you can do get diff had hollow 明确地指定你 可以做 diff had 空心文本
text okay yes uh-huh 好吧是的嗯嗯
44:31 so that's a good question it's like how can 所以这是一个很好的问题就像 你好点文
hello dot text be different than 本如何与
44:36 head because head refers to where you head 不同因为 head 指的是你 当前所在
currently are so to clarify head refers 的位置所以澄清 head 指的
44:40 to the last snapshot so like in my picture 是最后一个快照所以就像我的 照片 这里
here had and master are both had 和 master 都在
44:50 here and the current working directory is 这里,当前工作目录 有点独立于此,就
kind of independent of this like 像
44:55 you're going to delete all the files in here 你要删除这里的所有文件一样, 它不会
it doesn't change the history graph 更改历史图
44:58 or the references and so yeah you can 或引用,所以是的,你可以在 这里有差
have differences between here and here 异 在这里,
45:01 and at a high level this is how you work 在高层次上,这就是您处理 项目的方
on a project like you make some changes 式,就像您在这里进行一些更改一样,

about:blank 26/52
2023/5/11 15:40 For print

45:04 here you get add them to stage them and 您将它们添加到舞台上, 然后您提交并
then you get commit and that creates a
45:08 new snapshot here good question any 在此处创建一个新快照好问题 任何其他
other questions yep 问题是的,
45:25 so the question is does get actually save 所以问题是 确实以明显的方式实际 保存
all this stuff kind of in the 了所有这些东西,
45:30 obvious way or is it doing something 或者它做了一些更 有趣的事情答案是它
fancier the answer is is it is doing 正在做
45:33 something a little bit fancier but you can it 一些更有趣的事情但是你 可以它有一个
has an interface that lets you 界面让你
45:37 think of it like it stored that way in 认为它就像它那样存储在 practice get 使
practice get uses Delta compression it 用 Delta 压缩它
45:42 also does some other stuff but yeah the 也做一些其他的事情但是是的 磁盘表示
on disk representation is actually 实际上是
45:45 reasonably efficient question yeah that's 相当有效的问题是的这是 一个很好的问
a good question so the question 题所以问题
46:00 is here we were comparing the current 是我们正在比较当前 工作目录与
working directory with a particular
46:05 snapshot in the past can we compare two 过去的特定快照我们可以比较两个 快照
snapshots with each other like at two 彼此就像
46:09 different points in the history and yeah I 在历史上的两个不同点,是的, 我得到
get diff can take yet another argument 差异可以在这里接受另一个参数,
46:12 here so I can for example compare head 所以我可以例如比较 head 和它以错误的
with it did in the wrong order I can 顺序做的我可以
46:18 compare what change from here to head 比较从这里到 head 在 hello text 中的变
in hello text and it shows me that I added 化和 它告诉我我
46:23 the second line in there any other 在第二行添加了任何其他 问题
questions
46:41 yeah so the question is you're working on 是的,所以问题是你正在 Dropbox 文件
a shared project in a Dropbox folder 夹中处理共享项目,
46:44 and anyone a migrate to get does it make 任何要迁移的人将 Dropbox 文件夹变成
sense to turn the Dropbox folder into a
46:48 git repo do not use get inside dropbox git repo 是否有意义 不要使用 get inside
dropbox will corrupt your gate repo dropbox dropbox 会破坏你的 gate repo

46:52 there are good solutions to doing that 很好的解决方案可以做到这一点, 一个
one is just use github otherwise I talk 就是使用 github 否则我会
46:57 to me after class and there ways of using 在课后和我交谈,还有 使用 Dropbox 的
Dropbox as I get remote safely any 方法,因为我可以安全地远程访问任何
47:03 other questions 其他问题
47:06 next we're going to talk about branching 接下来我们将要 讨论分支 和合并,这是
and merging which is another powerful

about:blank 27/52
2023/5/11 15:40 For print

47:11 feature of get that you almost certainly get 的另一个强大功能,您几乎肯定会 在


use both when working on your own 处理自己的
47:15 projects and when collaborating with 项目时以及在与 其他人合作进行这一系
others for this series of demos we're 列演示时使用它们,而
47:19 going to rather than work with a simple 不是使用 实际编写的简单文本文件 一个
text file actually write a simple 简单的
47:24 computer program because it'll better 计算机程序,因为它将更好地 说明分支
illustrate the concepts of branching and 和合并的概念,
47:28 merging and as we go through this 并且在我们进行此 演示时,我们将牢记
demonstration we'll keep in mind how the
47:32 get interface commands connect to the 获取接口命令如何连接到 基础数据模型
underlying data model connect to objects 连接到对象
47:37 and references and how these 和引用以及这些命令如何 修改 这两个数
commands modify those two data 据结构让我可以
structures let me
47:44 do a get status to see the current state of 获取状态以查看 我的存储库的当前状态
my repository here I've modified 我已经修改了
47:47 hello text I actually don't really care about 问候文本我实际上不再关心 这个修改这
this modification anymore this is 是
47:51 some random file if I do get check out 一些随机文件如果我确实得到了对开 文
folio text this is another different use 本这个 是
47:57 of the check out command which check out 命令的另一种不同用法,它基
basically throws away the changes that 本上 丢弃了我
I've made
48:02 in the working directory and sets the 在工作目录中所做的更改,并将 hello 文
contents of hello text back to the way 本的内容设置回
48:07 it was in the snapshot that head points to 它在 head 指向的快照中的方式, 如果
if I like it get logged - - all - 我喜欢它被记录 - - 所有 -
48:12 graft - - decorate it'll show me that here I 嫁接 - - 装饰它会告诉我, 我在这里添加
added the initial attacks and it 了初始攻击,它
48:18 added that single line here and so now 在这里添加了那一行,所以现在 整个文
whole text doesn't have that third line 本没有
48:23 I'd added it just has the original - next 我添加的第三行它只有原来的 - 下一个
time we should write a very simple 是时候我们应该写一个非常简单的
48:28 program we'll call this program and a 程序了,我们称这个程序为 模具馅饼,
mold pie and let me just go ahead and 让我继续
48:34 write a program that it prints a little bit of 写一个程序, 当我运行它时它会打印一
output when I run it let's see 些输出让我们看看
48:45 [Applause] so when I run this program it [掌声] 所以当我运行它时 它运行的程序
runs main 主要
48:50 mean calls default and then let me go 意味着调用默认值然后让我继续前进 并
right ahead go ahead and define default 定义默认值

about:blank 28/52
2023/5/11 15:40 For print

48:54 and default is going it's just going to print 并且默认值正在运行它只会 打印你好所
hello so this is a program that 以这是一个
48:58 greets its user and so if I run animal dot 问候它的用户的程序所以如果我运行动
pi I'll see that it just prints 物 点pi我会看到 它只是打印
49:03 hello so that'll be our starting point if I do hello 所以这将是我们的起点, 如果我确
get status it shows me that 实获得状态它向我显示
49:07 animal dot hi is an untracked file to begin animal dot hi 是一个未跟踪的文件 开始
with i want this to be part of my 我希望它成为我
49:14 part of the snapshot so i'm going to get 快照的一部分所以我要 get add animal
add animal dot hi to add it to the dot hi 将它添加到
49:19 staging area and do then do a git commit 暂存区然后执行 git commit
49:24 here I'm going to write yet another 在这里我要写另一个 无用的提交消息
useless commit message don't actually
49:28 write commit messages like this in real 在实际项目中实际上不会写这样的提交
projects but for now this is fine so now 消息 但是现在这很好所以 现在
49:33 I have this basic animal dot pi and if I 我有这个基本的动物点 pi,如果我 现在
look at my get history now I have this 查看我的获取历史,我有这个
49:38 latest snapshot this is the commit hash 最新的快照,这是提交哈希 ,这是主分
and this is where the master branch is 支
49:43 pointing now we're actually way to 指向的地方,现在我们实际上是 演示如
demonstrate how to use git branches to 何使用 git 分支的方法
49:48 have parallel lines of development they 有平行的开发线他们 得到分支命令或分
get branch command or the branch 支子
49:53 sub-command is used to access 命令用于访问与 分支相关的功能只是
functionality related to branching just
49:57 running git branch by itself lists all the 运行 git 分支本身列出
branches that are present in the
50:00 local repository it can also take an extra 本地存储库中存在的所有分支它也可以
argument - V V to be extra verbose 接受一个 额外的参数 - V V 到
50:05 and print some extra information if we do 如果我们 得到分支然后指定
get branch and then specify the name
50:11 for a new branch git will create a new 新分支的名称,那么会更加冗长并打印
branch which is just a reference that 一些额外信息 git 将创建一个新 分支,它
只是一个指向
50:15 points the same place where we're 我们 当前正在查找的相同位置的引用,
currently looking so now there's a new 所以现在有一个新的
50:18 reference called cat reference in this 引用 在这种情况下称为 cat 引用与 分支
case is the same as branch there's a new 相同有一个
50:22 branch called cat which points to 名为 cat 的新分支指向 head 指向的任何
wherever head was pointing if I look at 地方如果我
50:26 the git log again I'll see that here had 再次查看 git 日志我会看到这里有 指向
points to master masters over here and master masters over here 的

about:blank 29/52
2023/5/11 15:40 For print

50:31 this is also where the cat branches so 地方 cat 分支,所以 现在我有两个分
now I have two branches two references 支,两个引用
50:35 that resolve to the same commit get is 解析到同一个提交 get 实际上不仅知道
actually aware of not only which
50:41 snapshot in the history are currently 历史中当前正在 查看的快照,所以指向
looking at so had points to this commit 这个提交,
50:44 but it's also aware of had kind of being 但它也知道有某种 关联 a 有一个分支,
associated with a with a branch so here 所以这里的
50:49 head is associated with master and it's head 与 master 相关联, 如果我创建一
the case that if I create a new snapshot 个新快照,
50:52 if I type git commit at this point the next 如果我在此时键入 git commit , 将创建
snapshot will be created and 下一个快照,
50:57 I'll point to that new snapshot master will 我将指向新的快照 master 将一起更新 用
be updated along with head if I do head 如果我
51:02 get checkout cat what this does is it 得到 checkout cat 它的作用是它 切换到
switches to the branch cat it replaces 分支 cat 它替换
51:07 the contents of the working directory 工作目录的内容而 不用任何猫指向它
without with whatever cats pointing to
51:11 which in this case is the same as the 在这种情况下与 之前的内容相同但现在
contents before but now if I look at the 如果我看
51:14 git log again now I have head point to cat git log 再次现在我有 head 指向 cat 而不
instead of master and then master 是 master 然后 master
51:20 also points to the same place the same 也指向同一个地方相同的底层 提交现在
underlying commit and now at this point 在这一点上
51:24 if I make changes to my current working 如果我更改我当前的工作 目录并进行新
directory and make a new commit the cat 的提交 cat
51:29 branch the cat pointer will be updated to 分支 cat 指针将更新 为指向你提交的位
point than you commit where as master 置,因为 master
51:33 will continue pointing wherever it pointed 将继续指向它 之前指向的任何地方所以
before so let me go ahead and 让我继续
51:36 modify animal PI to add some cat related 修改动物 PI 以添加一些与猫相关的 功能
functionality so I'm going to say that 所以我要说
51:41 if sISTAR V one is cat then run the cat 如果 sISTAR V 是猫然后运行 cat 函数否
function otherwise run the default 则运行默认
51:47 function and then let me go ahead and 函数然后让我继续导入 定义 cat 函数这
import define the cat function so cats 样猫就
51:52 don't say hello them you know so cat 不会打招呼你知道所以 cat 打印 meow
prints meow straightforward enough so 足够直接所以
51:58 now if I run animal dot PI and give it the 现在如果我运行 animal dot PI 并给它
cat argument it says meow if I give cat 参数 它说 meow 如果我给
52:03 it some other argument it defaults back to 它一些其他参数它默认返回 hello 好吧 如
the hello all right so simple change 此简单的更改

about:blank 30/52
2023/5/11 15:40 For print

52:07 I made if I do a get status that says that 我做了如果我做一个 get status 说 PI 已
animal that PI has been modified 被修改的动物
52:11 Farren get diff it'll show me what's Farren get diff 它会告诉我 自从 最后一
changed since the last commit 次提交
52:15 so here I've added this cat function 所以在这里我添加了这个以 绿色突出显
highlighted in green then also change 示的猫函数然后
52:19 the main function a little bit now here if I 现在在这里也稍微更改主要函数 如果我
do get add animal dot I get commit 确实得到添加动物点我得到提交
52:26 I mean actually you write a slightly more 我的意思是这次你写了一个 稍微有用的
useful commit message this time I'm 提交消息我' 我要
52:31 going to add cat functionality and now if I 添加 cat 功能,现在 如果我查看 git 日
look at the git log I see a little 志,
52:38 more stuff I'm going to show you one 我会看到更多的东西
more argument to this get logged
command
52:41 there's an argument - - one line one line -
spelled correctly which shows a
52:47 more compact representation of the 图形的更紧凑表示 因此应该是更有用的
graph so sould be a more useful thing to 东西,
use
52:51 because we're super zoomed into the 因为我们超级放大到 屏幕并且没有太多
screen and there isn't that much space 空间
52:54 to show a long commit history so here we 来显示很长的提交历史所以在这里我们
see the sequence of commits is still 看到提交顺序仍然是
52:59 linear and we have master still pointing 线性的并且 我们有 master 仍然指向 它
wherever it pointed before where we just 之前指向的任何地方,我们刚刚
53:03 had the basic underlying animal top high 拥有基本的底层动物顶级 功能,但现在
functionality but now we have this cat 我们有这个 cat
53:08 branch which adds the cat functionality 分支,它添加了 cat 功能, 例如,我们
we could for example get checkout 可以让 checkout master
master
53:14 to go back to the master branch and then 返回到 master 分支,然后 在这里如果
here if we look at animal dot pie it 我们看看 animal dot pie 它
53:19 doesn't have the cat functionality 不再具有 cat 功能 如果我们查看 git log
anymore if we look at the git log we'll 我们会
53:22 see that head is pointing to master so so 看到 head 指向 master 所以我们可以在
we can jump back and forth between
53:25 parallel lines of development so now that 平行的开发线之间来回跳转所以现在 我
we have the cat functionality 们有 cat 功能
53:30 suppose that we want to work on adding 假设我们想要并行添加 dog 功能,并
dog functionality in parallel and
53:33 suppose that in this case like the cat 假设在这种情况下 cat 功能正在开发中,
functionality is under development or 或者

about:blank 31/52
2023/5/11 15:40 For print

53:37 maybe somebody else is working on it so 可能其他人正在处理它,所以 我们只想


we just want to start from the base 从基础
53:39 master commit and build the dog master 提交开始并构建 dog 功能从那里
functionality starting from there so now 开始,所以现在
53:44 what do I want to do I want to create a 我想做什么我想创建一个 新的分支 dog
new branch dog for adding the dog 来添加与 dog
53:48 related functionality and I'll eventually 相关的功能,我 最终会在稍后合并它所
merge it in later so I can 以我可以
53:51 use the git branch dog command 使用 git branch dog 命令,然后 是 git
followed by the git checkout dog checkout dog 命令
command to
53:56 create a new dog branch and then check 创建一个新的 dog 分支然后 检查它实际
it out there's actually a short form for 上有一个简短的形式用于
54:00 this get checkout - b-dawg so this does 这个 get checkout - b-dawg 所以这确实
get branch dog get checkout dog and get branch dog get checkout dog 现在
now
54:06 if I look at my graph I have cat where it 如果我看我的图表我有 cat 它之前的位置
was before master where it was before master 以前的位置,
54:11 but now head instead of pointing to 但现在 head 而不是 像以前那样指向
master as it did before now head points master 现在 head
54:15 to this newly created dog reference which 指向这个新创建的 dog 引用, 它也在同
is also at the same commit so at 一个提交中,所以在
54:20 this base commit and now I'll go ahead 这个基本提交中,现在我将继续 添加我
and add my dog functionality so let me 的 dog 功能 所以让我
54:25 go and define my dog function dogs don't 去定义我的 dog 功能 dogs don't say
say hello they say woof and then I'll hello they say woof 然后我会
54:31 add some similar functionality here to 在这里添加一些类似的功能来 决定是运
decide whether to run default or dog so 行 default 还是 dog 所以
54:35 if the first argument is dog then I want to 如果第一个参数是 dog 那么我想 运行
run the dog function otherwise whoops dog function otherwise whoops
54:42 otherwise I want to run the default otherwise I want to run the default
function so here's what I've changed function 所以这是我对
54:49 with respect to the base commit master 指向的基本提交所做的更改所以
wherever master is pointing so I've 我添加了 dog
added the dog
54:53 function and I've changed mean a little bit 函数并且我改变了一点意思 所以有点平
so a kind of parallel modification 行 修改
54:56 to what I did in the cat branch let me go 我在 cat 分支中所做的让我 继续并获得
ahead and get add animal Titus add up 添加动物提图斯添加
55:02 to the staging area if I do get status I'll 到暂存区如果我确实获得状态 我将看到
see that this change will be 在
55:06 committed when I make the next commit 我进行下一次提交时将提交此更改 然后
and then I do get commit add 我确实得到 commit add

about:blank 32/52
2023/5/11 15:40 For print

55:11 functionality now when I look at the get functionality now 当我查看 get 图时,它
graph it actually looks kind of 实际上看起来
55:18 interesting compared to the ones we've 比我们 之前看到的更有趣,这表明这
looked at before this shows that these
55:22 three commits are in common with the 三个提交 与它之后的提交是相同的,
ones that come
55:25 after it but then the history is actually 但历史 实际上是分叉的 在这一点之后,
forked after this point and I 我
55:28 have this one commit that adds cat 有一个提交 在一条开发线中添加了 cat
functionality in one line of development 功能,
55:32 and then I have this other commit that 然后我有另一个提交 在另一条开发线中
adds dog functionality in this other 添加了 dog 功能
55:36 line of development and then using the ,然后使用 git checkout 命令我可以在
git checkout command I can switch back
55:39 and forth between dog and cat and dog 之间来回切换 和 cat 和 master 所以
master so this is great I can do 这很棒我可以在
development in
55:45 parallel on different features but this is 不同的功能上并行开发但这 只有在我
only really useful if I can
55:48 eventually combine those things back 最终可以将这些东西组合 回我原来的开
into my original line of development to 发线以便
55:52 have both features in a single version of 在我的源代码的单个版本中同时拥有这
my source code so the command that's 两个功能时才真正有用 所以
55:57 used to do that is get merge so like get 用于执行此操作的命令是 get merge,所
branch and get merge can kind of be 以像 get branch 和 get merge 可以被
56:01 thought of as opposites let me check out 认为是对立的
get check out master let me check out
my
56:09 master branch so now you see head 我想将
points to master and then I want to
merge the
56:13 cat functionality and the dog functionality cat 功能和 dog 功能合并到 master 中,
into master and to do that 为此
56:17 I can use the git merge command and 我可以使用 git merge 命令,get merge
get merge is actually pretty fancy and I 实际上非常花哨,我
can
56:21 actually merge cat and dog at the same 实际上可以同时合并 cat 和 dog 但是对
time but for this demonstration we're 于这个演示我们是
56:24 going to only merge one thing at a time 一次只合并一件事 所以首先我将输入 git
so first I'll type git merge cat and merge cat 并在
56:28 gets us some stuff here it says fast- 这里给我们一些东西它说 快进所以这里
forward so what is going on here 发生的事情
56:33 well this is one interesting thing that get 很好这是一件有趣的事情 当你在 一个特
can do when you're at a particular 定的

about:blank 33/52
2023/5/11 15:40 For print

56:38 commit and you merge some other 提交,你合并了一些其他分支, 其中其


branch in where that other branch has 他分支将
the
56:42 current commit as a predecessor it's not 当前提交作为前身它没有 必要创建任何
necessary to create any new snapshots 新快照或
or
56:48 do any other fancy stuff basically this this 做任何其他花哨的事情基本上 这个主分
master branch here this pointer to 支在这里这个指向
56:52 this commit can just be moved to point 这个提交的指针可以移动 指向 这里而不
here instead to incorporate that cat 是合并 cat
56:56 functionality and so if we look at the git 功能,因此如果我们 再次查看 git 日志,
log again we see that master is 我们会看到 master
57:02 basically pointing to the same places 基本上指向 cat 指向的相同位置,所以
wherever cat was pointing all right so
57:06 now we're on the master branch and it 现在我们在 master 分支上并且它 有 cat
has the cat functionality great we're 功能很棒,
57:09 halfway there if we look at animal dock 如果我们通过 animal dock 看 它有 cat
by it has the cat functionality but it's 功能但它
57:16 missing the dog stuff so let's try get 缺少 dog 的东西,我们就完成了一半所
merge dog next something a little bit 以让我们尝试 get merge dog 接下来
57:22 more interesting happens this time so 这次发生了一些更有趣的事情所以 这次
this time the branch can't be fast 分支不能 像
57:26 forwarded like it was before it's not that 以前一样快速转发它不是 一个东西
one thing which is strictly older
57:31 than the other thing there's been parallel 比另一个东西更旧有 并行开发可能
development that may be kind of
57:34 incompatible with the current set of 与当前的一组 更改不兼容并且
changes and
57:36 it does its best job at automatically 它在自动 合并来自另一个分支的更改方
merging the changes from this other 面做得最好
57:40 branch so it says Auto merging animal 所以它说 Auto merging animal dot pie
dot pie
57:43 but in this particular case there's what 但在这个特殊情况下有 所谓的合并冲突
was what's called a merge conflict so it 所以它
57:47 wasn't able to automatically resolve on 无法在调用时自动解决 这两个并行
the call the conflicts between these two
57:51 parallel branches of development and 开发分支之间的冲突, 这是你会看到的
this is something you'll see in practice 在实践中,
57:54 when you're working on real software 当你在处理真正的软件 项目时,它们很
projects and they're complicated 复杂,
57:57 slightly incompatible changes happening 同时发生了一些不兼容的变化, 所以在
in parallel so at this point it's left 这一点上,
58:02 up to the developer to fix this issue and 由开发人员来解决这个问题 并提供一些
get offers some functionality in 功能来

about:blank 34/52
2023/5/11 15:40 For print

58:07 order to help resolve merge conflicts 帮助解决合并冲突, 有一个 名为 git


there's a program called git merge tool merge 工具的程序,
58:12 and in my particular setup this will launch 在我的特定设置中,这将 启动 vim diff 实
vim diff actually this is not 际上这没有
58:17 configured them diff I think will start the 配置它们 diff 我认为将启动 正确的程序
right program let me set up my get 让我设置我的 get
58:31 to launch the correct tool actually let's 以启动正确的工具实际上 让我们跳过那
skip that part and let's just 部分让我们
58:38 manually look at this event if so there's a 手动看看 在这种情况下,如果有的话,
program called vim diff which 有 一个名为 vim diff 的程序
58:42 can be set up to be launched when you 可以设置为在您 输入 get merge tool 时
type in get merge tool which is a tool 启动,该工具是
58:45 that you use when you try get merged in 您尝试在合并冲突中合并时使用的工
there merge conflicts but in this 具, 但在这种
58:50 particular case we'll just manually resolve 特殊情况下我们将 只是手动 解决它们
them
58:52 so let me I did get merge - - abort so it 所以让我确实得到了合并 - - 中止所以 它
put me back in the state I was before 让我回到了
58:57 I tried that git merge so this is the current 我尝试 git merge 之前的状态所以这是
state of my repository I'm back 我的存储库的当前状态我回到了
59:00 to the case where master is at the same 主人所在的情况 和猫在同一个地方,我
place as cat and I'm about to merge in 即将合并到
59:04 dog so I do get merged dog and it says 狗中,所以我确实得到了合并狗,它说
conflict merge conflict in animal Pi so 动物 Pi 中的冲突合并冲突所以让
59:10 let's just look at animal dot PI directly so 我们直接看动物点 PI 看起来这个顶部
it looks like this top part
59:16 looks pretty reasonable it has both the 看起来很合理它有 cat 函数和 dog 函数
cat function and the dog function which 都
59:20 is exactly what I want but now I see some 正是我想要的,但现在我 在 main 中看
weird stuff in main and this is 到了一些奇怪的东西,这是
59:24 where I add slightly incompatible 我添加了稍微不兼容的 更改的地方,所
changes so here it says that in one 以这里它说在一
59:28 thing like basically the branch you were 件事上基本上就像你所在的分支 你有这
on you had this content and then the 个 content 然后
59:34 branch you're trying to merge had this 你试图合并的分支有这个 内容然后这些
content and then these things here the 东西在这里
59:38 angle brackets and the equals our 尖括号和等于我们的 冲突标记所以这是
conflict markers so this is where you 你
59:43 were and this is the thing you're trying to 所在的地方这是你试图 合并的东西它基
merge in and it's basically saying 本上是说 在
59:45 that it was this on one case this in the 一种情况下是这样,在 另一种情况下是
other case and it doesn't really know 这样,它真的不知道

about:blank 35/52
2023/5/11 15:40 For print

59:49 how to resolve these two and it's left up 如何解决 这两个问题,这留给
to the
59:51 programmer to fix this problem so in this 程序员来解决这个问题,所以在 这种特
particular case we can go ahead and 殊情况下,我们可以继续
59:55 delete the conflict markers and then turns 删除冲突标记和 然后事实 证明,我们实
out that we can actually 际上可以将
59:59 concatenate this code together and does 这段代码连接在一起并做 正确的事情也
the right thing maybe we want to make a 许我们想做一个
1:00:03 small change like this should be an if this 小的改变,比如 this should be an if this
should be an else--if and this should be an else--if and this
1:00:07 should be an else that might make a little should be an else that might make a
bit more sense actually I think little bit 实际上更有意义我认为
1:00:12 it's necessary for correctness here so the 这里的正确性是必要的所以 程序员需要
programmer needed to modify the code 稍微修改代码
1:00:16 a little bit in order to make it sensible 以使其 在合并在一起时变得合理但是
when it's merged together but
1:00:20 once the programmer has fixed the 一旦程序员修复了合并 冲突修复了
merge conflicts fixed the stuff between
the
1:00:25 conflict markers you can save this file 冲突标记之间的东西你可以保存 这个文
and we can do get merged - - continue to 件, 我们可以合并 - - 继续
1:00:30 tell git that we fix the issues it's 告诉 git 我们解决了问题, 有必要重新添
necessary to re add animal PI to tell 加动物 PI 告诉
1:00:37 git that we've actually fixed these issues git 我们实际上已经解决了这些 问题,然
and then we need to get merged - 后我们需要合并 -
1:00:41 - continue it pops up an editor and we - 继续它弹出 一个编辑器,我们 可以为
can give a commit message for this new 我们即将创建的这个新提交提供一个提
交消息
1:00:44 commit that we're about to create and , 现在如果我们查看 git 历史,我们
now if we look at the git history we
1:00:48 have the single commit that represents 有一个提交代表 我们刚刚进行的合并提
our merge commit that we just made 交,它
which
1:00:55 merges in the dog functionality and here 合并了 dog 功能和 这里有 dog commit
this has as parents both the dog commit
1:01:02 and the cat commit so both these 和 cat commit 作为父母, 所以这两个分
branches appear in our 支从这一点开始出现在我们的
1:01:05 history from this point backwards and this 历史记录中, 我们正在进行的当前提交
current commit that we're on
1:01:09 incorporates the functionality from both of 结合了 这两个分支的功能,所以如果我
these branches so if we run animal 们运行 animal
1:01:15 duck fight with cat it does the cat thing if duck fight cat 如果我们用 dog 运行它,
we run it with dog it does the 它会做 cat 的事情

about:blank 36/52
2023/5/11 15:40 For print

1:01:18 dog thing and if we run it with anything ,它会做 dog 的事情,如果我们用其他
else it falls back to the default 任何东西运行它, 它会回退到默认
1:01:21 implementation so this is a demonstration 实现,所以这是一个 演示,展示了你如
of how you branch and get 何分支并开始
1:01:26 to do development on different things in 在不同的事情上进行开发 并行,然后如
parallel and then how you can use the 何使用
1:01:30 merge command and get to resolve 合并命令来解析这些 不同的分支并将它
those different branches and combine 们组合到
them
1:01:34 together into a single snapshot that 一个快照中,其中 包括彼此并行开发的
includes all the functionality that was 所有功能
1:01:37 developed in parallel with each other and ,然后在您执行操作时可能发生的一件
then one thing that can happen when 事
1:01:43 you're doing get branching and merging 得到分支和合并 是你遇到合并冲突,
is you run into merge conflicts and
1:01:47 these conflicts show up as conflict 这些冲突显示为冲突 标记和文本文件,
markers and text files you can manually 你可以手动
1:01:51 resolve them and kit also has some tools 解决它们,工具包也有一些工具 可以帮
that can help with this though these 助解决这个问题,尽管这些
1:01:55 tools are kind of advanced and will only 工具有点高级,只会 引用它们 在讲义中
refer to them in the lecture notes and 并
1:01:58 not actually demonstrate them for you so 没有实际为您演示它们, 所以分支和合
that's get branching and merging 并
1:02:03 any questions no great so moving on to 任何问题都不是很好所以继续 本讲座的
the next topic of this lecture we will 下一个主题我们将
1:02:12 talk about git remotes so this is basically 讨论 git remotes 所以这 基本上是您
how you collaborate with other
1:02:15 people using git a git repository the stuff 使用 git a 与其他人协作的方式 git 存储
contained in this dot git folder 库 这个点 git 文件夹中包含的东西
1:02:21 represents kind of an entire copy of the 代表了历史的完整副本, 它具有引用中
history it has the objects in the 的对象
1:02:26 references and contains all the previous 并包含所有以前的 快照,并且您
snapshots and the way you collaborate
1:02:30 with other people using git is that other 使用 git 与其他人协作的方式是 其他人也
people can also have copies of the 可以拥有副本
1:02:34 entire git repository and then your get 整个 git 存储库,然后你的 get copy
copy your local instantiation of the
1:02:41 repository can be aware of the existence 存储库的本地实例可以知道 同一存储库
of other clones of the same repository 的其他克隆的存在
1:02:46 and this is a concept known as remotes ,这是一个称为远程的概念, 因此 git
so the git remote command will list all remote 命令将列出
1:02:51 the remotes that git is aware of for the git 的所有远程 知道 当前存储库,在我们
current repository and in our case with 的例子中使用

about:blank 37/52
2023/5/11 15:40 For print

1:02:57 this repository right here this command 这个存储库,这个命令 get remote 只是
get remote just doesn't print anything 不打印任何东西,
1:03:01 because we haven't configured any 因为我们没有配置任何 远程它只知道
remotes it is only aware of the single
1:03:05 local copy of the repository that we're 我们正在工作的存储库的单个本地副本
working with here but in practice if 在这里,但实际上如果
1:03:09 you're collaborating with other people 你与其他人合作, 你的 git 可能知道
your git might be aware of the copy of
1:03:13 the code that is on github and then github 上的代码副本,然后 有一组命令
there's a set of commands to send 将
1:03:17 changes from your local copy of the 更改从你的本地 存储库副本发送到你的
repository to a remote that your get is 远程 例如,get
1:03:21 aware of so sending stuff from your 知道从你的计算机发送东西 到 github,
computer to github for example and
1:03:24 there's another set of commands for 还有另一组命令用于 获取在本地存储库
fetching changes made in a local 中所做的更改,以将
1:03:28 repository to get changes from github into github 中的更改获取 到你自己的本地副
your own local copy in this 本中,在这个
1:03:34 demonstration here we actually won't go 演示中我们实际上不会去 配置 一个
and configure a github account and log github帐户并
1:03:38 in and create a new repository on there 登录并在那里创建一个新的存储库 你可
you can find other tutorials for doing 以找到其他教程来做这件事
1:03:42 that we'll actually just use a separate 我们实际上只是 在同一台计算机上使用
folder on the same computer and treat it 一个单独的文件夹并将它当作
1:03:46 like a git remote so let me I'm in the 一个git remote所以让我在 演示中 这里
demo folder here let me go up one 的文件夹让我上一个
1:03:52 directory I have a directory called 目录 我有一个名为 playground 的目录,
playground that has this demo folder and 其中有这个演示文件夹,
1:03:56 I'll go ahead and create a new directory 我将继续在这里创建一个新目录, 我将
in here and I'll call it remote and then 其称为 remote 然后
1:04:04 do get in it - - bear in here those are the 进入它 - - 在这里 这些是 你可能永远
command that you'll probably never
1:04:08 need to use in regular usage but now 不需要在常规使用中使用的命令,但现
what I've done is made remote into a 在 我所做的是远程进入一个
1:04:13 folder that's appropriate to use as a git 适合用作 git 远程的文件夹
remote
1:04:16 so now going back into my demo folder 所以现在回到我的演示文件夹 可能意味
here might mean repository I can do get 着存储库我 可以使用 get
1:04:22 remote to list the remotes there's nothing remote 来列出遥控器 目前还没有任何东
yet but I can use the 西,但我可以使用
1:04:26 git remote add functionality to make my git remote add 功能让我的 本地存储库知
local repository aware of the existence 道

about:blank 38/52
2023/5/11 15:40 For print

1:04:31 of a remote so I can do git remote add 遥控器的存在,这样我就可以执行 git


and then the format for this is that remote add 然后格式是
1:04:37 remotes have names and then they have 遥控器有名称 然后他们有一个 URL,所
a URL so in this case I'll use the name 以在这种情况下,如果你只使用一个,
我将使用名称
1:04:42 origin does often use by convention as origin 通常按惯例用作 远程的名称,
the name of the remote if you're only
1:04:46 using one and then for the URL normally 然后对于 URL,通常 这将类似于 github
this will be like a github URL or URL 或
1:04:51 something like that or bitbucket URL or 其他东西 如果您使用的是在线存储库托
get live URL if you're using an online 管服务,则喜欢那个或 bitbucket URL 或
获取实时 URL
1:04:55 repository hosting service but in this case 但在这种 情况下,它只是我本地计算机
it's just a path to a folder on my 上文件夹的路径,
1:05:00 local machine there's a folder in the 父目录中有一个名为 remote 的文件夹将
parent directory called remote that will
1:05:04 act as the git remote for this repository so 充当 git 远程 对于这个 存储库,现在一
now once I've done that 旦我完成了,
1:05:08 there's a set of commands for interacting 就有一组命令可以 与这个远程交互,一
with this remote one command 个
1:05:13 that's useful is the git push command this 有用的命令是 git push 命令, 这个命令
command can send the changes from 可以将更改从
1:05:18 your computer to the remote and the 你的计算机发送到远程, 这个命令的格
format for this command is that git push 式是 git push
1:05:22 takes in the name of a remote and then it 接受远程名称,然后 接受本地分支名
takes in a local branch name : a 称:
1:05:27 remote branch name and what it does is 远程分支名称,它所做的是 创建一个新
it creates a new branch or updates a 分支或使用
1:05:31 branch on the remote with the name 此处指定的名称更新远程分支并将其设
specified here and sets it to the 置为
1:05:36 contents of the branch specified here so 这里指定的分支的内容,所以 具体使用
a concrete use of this might look like 它可能看起来像
1:05:41 git push I've only one remote called origin git push 我只有一个远程调用 origin 然后
and then what should I push let 我应该推送什么让
1:05:48 me look at my history graph I have a 我看看我的历史图表我有 一堆我可以推
bunch of things I could push let me get 送的东西让我得到
1:05:53 pushed to origin the master branch from 从 我的本地机器推送到 master 分支:
my local machine :
1:05:58 master so I want to create a branch on master 所以我想在远程机器上创建一个
the remote machine with the name 名称为 master 的分支,
master
1:06:03 that is going to be the same as the 它与 我本地机器上的 master 分支相同所
master branch on my local machine so 以让
let
about:blank 39/52
2023/5/11 15:40 For print

1:06:08 me go ahead and run that command it 我继续运行它 命令它 打印出一些东西并


prints out some stuff and it says on the 且它说在
1:06:12 remote I created a new branch remote 远程我创建了一个新的分支远程 主控点
master points to the same branch as 指向与
1:06:16 master on my local machine and now if I 我本地机器上的主控相同的分支现在如
do a git log it shows me so in blue is 果我 执行 git log 它会显示我所以蓝色是
1:06:23 head where I currently am in green are 我现在所在的位置 绿色是 我本地 git 存
all the branches in my local git 储库中的所有分支
1:06:27 repository and now we see one new color ,现在我们 在这里看到一种我们
here that we had
1:06:30 seen before so in red get shows 以前见过的新颜色,所以红色 get 显示了
references that are present on the
1:06:34 remotes that my local copy is aware of so 我的本地副本知道的远程上存在的引
on the remote origin there's also a 用, 所以在远程源上也有 一个
1:06:39 branch that happens to have the name 恰好名称为 master 的分支指向与
master that points to the same place as
1:06:43 my local branch master points and so 我的本地分支 master 点相同的位置,所
now if I make updates to my local copies 以现在 如果我更新我的本地副本,
1:06:49 like suppose here I go in and change the 就像假设我进入并更改 这些东西的大
capitalization of these things and then 写,然后
1:06:56 get had animal dot hi get commit here's a 得到动物 dot hi get commit 这是 提交消
short form for commit with a message 息的简短形式,
1:07:01 so it doesn't pop up the editor I'll give it a 因此它不会弹出编辑器
late and commit message and
1:07:04 now if I look at the git graph now I see 这里有新的快照,
that I've created this new snapshot here
1:07:10 that has this lower casing stuff in it but 里面有这个小外壳的东西, 但 origin
origin master is still back here so master 仍然回到这里,所以
1:07:15 if somebody else looks at the remote 如果其他人看遥控器, 他们只会看到到
they will only see the changes up to
1:07:20 here and we can actually demonstrate 这里的变化,我们实际上可以演示 这个
this functionality so let me go ahead 功能,所以让我继续
1:07:23 and open up a new tab here and go into 打开 在此处打开一个新选项卡并进入 我
my playground directory the git clone 的 playground 目录 git clone
1:07:29 command is a command that somebody 命令是一个命令,有人可以 使用该命令
can use to start from some copy of a 从某个存储库的某个副本开始
1:07:34 repository somewhere and make their 并制作他们自己的 本地副本,因此这通
own local copy so this is often a 常是
command to
1:07:38 use when starting out with a git repo like 在开始使用 git 时使用的命令 repo 就像
there might be something available github 上可能有一些可用的东西
1:07:41 on github and you want to copy it all in ,你想把它全部复制到 你的机器上以便
your machine in order to look at it or 查看它或

about:blank 40/52
2023/5/11 15:40 For print

1:07:45 start doing development and so the 开始进行开发,所以 git clone 的格式是
format for git clone is that it takes in 它接受
1:07:49 a URL and then it takes in a name for a 一个 URL,然后接受一个名字 对于 克隆
folder for where to clone it so in our 它的文件夹所以在我们的
1:07:55 case here we're just going to clone from 例子中我们只是从 这个远程目录克隆我
this remote directory we're pretending 们假装
1:07:59 that this remote folder is actually a 这个远程文件夹实际上是一个 远程机器
remote machine and then we're all clone 然后我们都将
1:08:03 it into the folder called demo two so 它克隆到名为 demo 的文件夹中 两个所
cloning into demo 2 done and I'm going 以 克隆到演示 2 完成,我
1:08:10 to CD into that directory and then now 将 CD 进入该目录然后现在 在这里我将
here I'm going to rename these tabs at 重命名底部的这些选项卡
1:08:14 the bottom I will say this one's machine 我会说这个是机器 一个,这个也是机器
one and this one's machine too so you 所以你
1:08:21 can think of these as two different people 可以想到这些 作为 不同机器上的两个不
on different machines with their 同的人,他们有
1:08:25 own copy of the repository and they're 自己的存储库副本,并且他们 都与单个
both interacting with the single remote 远程交互,
1:08:29 so if I do my get log command that I've 所以如果我执行我 一直在机器 1 上执行
been doing on machine one I see on 的 get log 命令,我在
1:08:34 Machine 2 I see this portion of the history 机器 2 上看到我看到这部分 历史,所以
so master on machine 2 is 机器 2 上的 master
1:08:41 pointing to the same places origin master 指向同一个地方 origin master
1:08:44 and it says merge branch dog so if I look 并且它说合并分支狗所以如果我 在这里
at animal dot pie here 看动物点派,
1:08:49 it doesn't have the changes that I made 它没有我 在机器上所做的更改,即使有
on machine to even though there are
1:08:53 sorry on machine one where I have this 抱歉 一台机器,我有这个 新提交,它只
new commit that is only present on this 存在于这台
1:08:58 machine but not on the remote and not 机器上,但不存在于远程机器上,也不
on machine too so if I want to fix that if 存在于 机器上,所以如果我想修复它,
如果
1:09:03 I want to send these changes up to the 我想将这些更改发送到 远程,就像将它
remote like think of it as sending it up 视为发送它一样
1:09:06 to github err up to the machine that's 到 github err 到 持有或维护源代码的机
holding or maintaining the source code I 器我
1:09:11 can use the git push command again git 可以再次使用 git push 命令 git push
push origin master colon master and this origin master colon master 这
1:09:18 will work but this is kind of annoying to 会起作用但是 每次你想这样做时这有点
type every time you want to do this 烦人
1:09:21 like this is a really common operation so 是一个非常常见的操作, 所以 git 有一种
git has a way of making this a little 方法可以使它变得更
about:blank 41/52
2023/5/11 15:40 For print

1:09:26 bit simpler it has a way of maintaining 简单它有一种方法来维护你


relationships between branches on your
1:09:31 own local machine and branches on 自己本地机器上的分支和远程机器上的
remote machines it is a way of knowing 分支之间的关系 它是一种了解
what
1:09:36 branch on a remote machine a local 远程机器上的哪个分支是本地分支的方
branch corresponds to so that you can 法 branch 对应于这样你就可以
1:09:41 type in a shortened version of git push 输入一个缩短版本的 git push 并且它会
and it'll know what all the arguments to 知道扩展形式的所有参数
1:09:45 the expanded form would have been and 是什么并且 有几种不同的语法可以
there a couple different syntaxes for
1:09:49 doing this one way is to use the git 做到这一点一种方法是使用 git branch - -
branch - - set up stream to command and 设置流命令,
1:09:55 what this does is for the branch that's 这是针对 当前检出的分支,它是主分
currently checked out which is master it 支,它将
1:09:59 will set the upstream - and I'll type in 设置上游 - 我将输入 origin master,现在
origin master and see now it says branch 看到它说 branch
1:10:05 master set up to track remote branch master set up to track remote branch
master from origin now if I type in get master from origin 现在,如果我输入
get
1:10:09 branch - VV remember this is tell me branch - VV,请记住这是以非常详细的
about all the branches that I know about 方式告诉我 我知道的所有分支,这
1:10:13 in a very verbose way that's what the - 就是 - VV 意味着我在本地机器上有三个
VV means I have three branches on my 分支,
1:10:17 local machine on machine one I have cat 在一台机器上我有 cat dog 和 master 我
dog and master and master on my local 本地机器上的 master
1:10:23 machine corresponds to origin master so 对应于 origin master 所以 现在我可以输
now I can type in just get push without 入 just get push 没有
1:10:30 all the extra arguments I could have done 所有额外的参数我可以 像 git push origin
this as git push origin master master
1:10:33 colon master but it wasn't necessary it'll colon master 那样做但是没有必要 它会
know that I want to push to origin 知道我想要 推送到 origin
1:10:38 master and it will make that change so master 它将进行更改, 所以现在这些更
now these changes are present on the 改存在于
1:10:42 remote we can go over to machine to 远程我们可以转到机器上 假装我们是另
pretend we're the other guy interacting 一个
1:10:46 with this repository and if I do might get 与此存储库交互的人,如果我这样做可
logged command I still don't see the 能 会记录命令我仍然没有 查看
1:10:51 changes so what's going on here well it's 更改 所以这里发生了什么 有 必要运行一
necessary in order to run a 个
1:10:55 separate command or it's necessary to 单独的命令, 或者有必要运行一个单独
run a separate 的

about:blank 42/52
2023/5/11 15:40 For print

1:10:58 command in order to have these changes 命令,以便 默认情况下在此处显示这些


present here by default all the get 更改 所有 get
1:11:03 commands don't talk to the internet it all 命令都不会与互联网通信 它 一切正常 在
works locally which means it works 本地,这意味着它工作得
1:11:06 very fast but then there are special 非常快,但是有一些特殊的 命令表示您
commands for saying that you want to 想要
1:11:09 retrieve changes that have made 检索在 其他地方所做的更改,而
somewhere else and the command that's
1:11:13 used for doing that is a command called 用于执行此操作的命令是一个名为 git
git fetch get fetch takes thee as an fetch get fetch 的命令,它将您作为
1:11:18 argument the name of the remote but if 参数名称 远程,但如果只有 一个,它只
there's only one it'll just use that so 会使用它,这样
1:11:22 you can type in git fetch and then it's 你就可以输入 git fetch,然后它会 与这
talked to this remote repository and it 个远程存储库对话,它
1:11:29 says that there's some update on the 说远程上有一些更新 ,我们可以通过
remote and we can visualize it by
1:11:34 running git log and now we see here 运行 git log 来可视化它,现在我们 在这
another situation that we hadn't seen 里看到 另一种情况,我们在
1:11:38 before we have master on our local 本地机器上拥有 master 之前我们没有见
machine the master branch doesn't 过 master 分支不会改变
change
1:11:42 the git fetch command doesn't change git fetch 命令不会改变 我们的任何本地
any of our local history our local 历史我们的本地
1:11:47 references like our branches but now it's 引用,比如我们的分支,但现在 它知道
aware that origin master has been origin master 已
1:11:51 updated to point to this new commit and 更新为指向这个新提交并且 有一个单独
there's a separate command we can do 的命令我们可以执行 get
get
1:11:56 merge in order to move master up to merge 以便将 master 移动到这里 或者
here or there's another command called 还有另一个命令称为 get
get
1:12:03 pull which is the same as doing git fetch pull 与执行 git fetch 然后 get merge 相同
and then get merge so if we just 所以如果我们
1:12:09 do get pull here for example it will say it's 只是在这里拉,例如它会说它 的快速转
fast forwarding is merging in 发正在将
1:12:13 origin master into our master and now if origin master 合并到我们的 master 中,
we look at the git history graph we've 现在如果 我们查看 git 历史图,我们
1:12:20 currently checked out master master 目前已经检查了 master master 指向与我
points to the same place as the origin 们的 origin master 相同的位置
1:12:24 master that we're aware of and all the 我知道并且 机器 2 和机器 1 之间的所有
changes between Machine 2 and 更改
Machine 1
1:12:27 are in sync so those are the basic 都是同步的,所以这些是 与 git
commands for interacting with git

about:blank 43/52
2023/5/11 15:40 For print

1:12:31 remotes so there's the git remote 遥控器交互的基本命令,所以有 git


command for listing remotes and adding remote 命令用于列出遥控器并添加
1:12:35 and removing them and things like that 和删除它们等等, 然后是 git push 命令
and then there's the git push command
1:12:40 for sending changes from your local copy 用于将更改从存储库的本地副本发送 到
of the repository to the remote and then 远程,然后
1:12:45 there's the git fetch command which is for 有 git fetch 命令 用于检索远程存储库的
retrieving changes to a repository 更改
1:12:48 that are present on a remote and getting 并 在本地计算机上获取更改,
the changes on your local machine and
1:12:54 once you retrieve those changes you can 一旦检索到这些 更改你可以 使用 git
use git merge to update your local merge 来更新你的本地
1:12:58 branch to point to the same place where 分支以指向 远程分支所在的相同位置,
the remote branch does or you can use 或者你可以使用
1:13:03 the git pull command which does git pull 命令,它的 作用与 get fetch
basically the same thing as get fetch
1:13:06 plus git merge and then of course 和 git merge 基本相同,然后当然 与所
separate from all these commands 有这些分开 commands
1:13:10 is the clone command that we talked 是我们刚才讨论的克隆命令, 它用于
about a little while ago which is for
1:13:14 taking a copy of remote repository and 获取远程存储库的副本并 从该副本初始
initializing the local repository from 化本地存储库,
1:13:19 that copy so that's a quick overview of 因此这是对 用于
the different commands used to interact
1:13:25 with git remotes and now these are kind 与 git remotes 交互的不同命令的快速概
of complicated and it takes a while to 述,现在这些都是很好的 的复杂性,需
要一段时间才能
1:13:29 master all the different variations of this 掌握它的所有不同变体 并了解它们
and understand how they're actually
1:13:32 used in practice but hopefully this acts as 在实践中的实际使用方式,但希望这 是
a quick introduction and you can see 一个快速介绍,您可以看到
1:13:36 how the different commands relate to the 不同的命令如何与 所有这些命令的底层
underlying data model all these 数据模型相关联
commands
1:13:40 all they do is fetch new objects from other 他们所做的只是从其他地方获取新对象
places or send objects from the 或将对象从
1:13:44 local mission to other places and these 本地任务发送到其他地方,这些 命令会
commands mutate references so relating 改变引用,因此将
1:13:51 these relating the interface of git and 这些与 git 的接口相关联,并将这些设计
some of these kind of badly designed 糟糕的
1:13:56 commands to the underlying data model 命令中的一些与底层数据模型相关联 可
can help it make a lot more sense the 以帮助它 更有意义的是,
1:14:03 final topic we're going to cover today is 我们今天要讨论的最后一个主题 是对
it's a kind of overview of other
about:blank 44/52
2023/5/11 15:40 For print

1:14:09 things that get can do that we're not get 可以做的其他事情的一种概述,我们
going to go into detail in teaching you 不会在教你
1:14:12 how to do but we just want to tell you that 如何做的过程中详细介绍,但我们只是
these functionalities exist in case 想告诉你 你 知道这些功能存在,以防
1:14:16 you need to do these things yourself you 你需要自己做这些事情你 可以查看文档
can look up the documentation and find 并
1:14:19 out exactly how to do it one thing is the 找出确切的操作方法一件事是 git config
git config command like a lot of 命令,就像
1:14:24 tools we've looked at like the shell and T 我们看过的很多工具一样,比如 shell 和
MUX and things like that T MUX 和 git 之类的东西
1:14:27 git is highly configurable and it's 是高度可配置的,它是 使用纯文本文件
configured using a plain text file which 配置的,可以
1:14:32 can be edited either through the 通过 命令行界面进行编辑,因此 git
command-line interface so git config can config 可以
1:14:35 take in flags that will modify this text file 接受将修改此文本 文件的标志,或者您
or you can edit the dot git config 可以编辑点 ​git 配置
1:14:40 file in the home folder with plain text 文件 在带有纯文本配置的主文件夹中,
configuration and so for this lecture 因此对于本次讲座,
1:14:47 I've actually cut out most of them I get 我实际上已经删除了其中的大部分内
config and only left in my username and 容,我得到了 配置,只留在了我的用户
名和
1:14:52 email for what will go in to get commits 电子邮件中,用于获取提交的内容, 但
but there's a lot of stuff you can put 是您可以放置​​很多东西
1:14:56 in here which will make it behave nicer it 在这里这将使它表现得更好 它按照你想
behaved the way you want it to and 要的方式表现并且
1:15:01 you can look online for different ways 你可以在线查找 人们配置他们的获取配
people have configured their get configs 置的不同方式
1:15:04 oftentimes people have documentation in 通常人们在 他们的套件配置中有文档
their kit configs
1:15:07 which can be found on github there's a 可以在github上找到还有一些 其他随机
couple other random commands that 命令 这可能
could
1:15:14 be useful one is for when you want to 是有用的一个是当你想用 git clone 克隆
clone a repository with git clone that's 一个存储库时,它
1:15:18 really gigantic get cloned by default 真的是巨大的,默认情况下被克隆复制
copies the entire version history for
1:15:24 the remote it's downloading the 远程的整个版本历史,它正在 从中下载
repository from but there's an argument 存储库,但是有一个
1:15:28 you can pass it which is - - shallow which 你可以传递它的参数是 - - shallow 这将
will avoid doing that so if 避免这样做,所以如果
1:15:32 there's some copy of some code on github 上有一些代码的副本, 说你想
github say that you want to get a copy
copy of

about:blank 45/52
2023/5/11 15:40 For print

1:15:35 on your local machine but that repository 在本地机器上获得一份副本,但该 存储


is really gigantic and has a 库确实非常庞大并且有
1:15:38 billion commits he's get cloned - - shallow 十亿次提交,他被克隆了 - - 浅这将是很
this will be much faster but 多 更快但是
1:15:42 then of course he won't have the version 当然他不会在 你的本地机器上有版本历
history on your local machine you'll 史你
1:15:45 just have the latest snapshot another 只会有最新的快照另一个 我们发现在实
command that we find really useful when 际软件项目上进行开发时非常有用的命

1:15:51 doing development on real software 是
projects is an interactive version of
1:15:55 the git add command so to demonstrate git add 命令的交互式版本所以 证明 这一
this I'm going to go ahead and make a 点我将继续对
1:15:59 couple different changes to my animal PI 我的动物 PI 进行一些不同的更改,其中
one change I'll make here I'll change 一个更改我将在此处更改我将在
1:16:05 some text here and then I'll put a new 此处更改一些文本,然后我将在此处放
print statement here so let's pretend 置一个新的 打印语句所以让我们假设
1:16:10 that this first change was some real 这是第一个 更改是一些真正的 更改,我
change I wanted to make say it's a bug 想说这是一个错误
1:16:13 fix and this other change here was a 修复,这里的另一个更改是 我为调试添
printf that I added for debugging but I 加的 printf,但
1:16:18 don't actually want to commit in the next 如果我执行 get diff,我实际上不想在下
snapshot if I do a get diff it'll 一个快照中提交它会
1:16:21 show me that yes I've made these two 显示 我是的,我已经做了这两个 更改,
changes and if I do get add animal dot 如果我确实获得了 add animal dot
1:16:25 pi it will stage both of those changes for a pi,它将暂存这两个更改 以进行提交,
commit and that's not what I want 这不是我想要的,
1:16:30 I could go manually remove this debug 我可以手动删除此调试 打印,然后执行
print and then do this get animal dog 此操作 get animal dog
1:16:34 get add animal dot PI but there's an get add animal dot PI 但有一个 更简单
easier way to do it 的方法来做到这一点有
1:16:38 there's this get add - pika man which lets 这个 get add - pika man 这 让我可以交
me interactively stage pieces of 互地暂存
1:16:43 files for it commit and so there's some 文件片段,所以有一些 界面可以处理这
interface for working with this so here 个所以这里说
1:16:46 it's saying do I want to stage both of 我想同时暂存这两个文件 这些更改中的
these changes and no I don't but I'm 一些,不,我不想,但我
1:16:49 going to split it into two smaller changes 要把它分成两个较小的 更改,这个我确
this one I do want to keep so I 实想保留,所以我
1:16:53 say Y for yes and this one I don't want to 说 Y 表示是,这个我不想 保留,所以我
keep so I say n for no and then if I 说 n 表示否 然后如果我

about:blank 46/52
2023/5/11 15:40 For print

1:16:57 do get diff - - cached this will show me 确实得到差异 - - 缓存这将告诉我 准备提
what changes are staged for commit so 交的更改所以
1:17:04 now it shows only the actual change I 现在它只显示我 想要保留的实际更改如
wanted to keep if I do get diff it'll 果我确实得到差异它
1:17:07 still show me the other change that is not 仍然会告诉我其他 没有进行的更改 成为
going to be part of the next the 下一个下
1:17:12 next commit which is the change I didn't 一次提交的一部分,这是我 不想保留的
want to keep and then with this I can do 更改,然后有了这个我可以
1:17:16 get commit specify some commit 得到提交指定一些提交消息 现在我只剩
message now I only have this change left 下这个更改
and
1:17:21 then I can do get check out animal to 然后我可以检查动物 apply to throw
apply to throw away this change so get away this change so get
1:17:26 add - P for interactive staging is a useful add -P for interactive staging is a useful
thing a couple other commands thing of other commands
1:17:31 that you can look up on your own are the that you can look to your own are the
get blame command so this commands get blame command 所以这个命令
kind
1:17:36 of ominous but it can be used to figure 有点不祥,但它可以用来确定 谁编辑了
who edited what line of a file and you 文件的哪一行,您
1:17:40 can also find the corresponding commit 还可以找到 负责修改
that was responsible for modifying that
1:17:44 particular line of that file and then you 该文件的特定行的相应提交,然后 您可
can look up commit messages 以查找
1:17:46 associated with that and whatnot so this 与该行关联的提交消息等等,所以 在我
is not that interesting to do in our 们
1:17:50 current toy repository but I'll go over to 当前的玩具存储库中做这件事并不是那
the repository for the class website 么有趣 但是我会转到 课程网站的存储库
1:17:54 and we can look at some particular file ,我们可以在这里查看一些特定的文
here and let me go to some particular 件, 让我转到这里的一些特定的行
1:17:59 line here and I can be looking at this me ,我可以像这样看这个 我哦,为什么这
like oh why was this particular line 个特定的行
1:18:03 added what does it mean and I can look 添加了它是什么 意思是,我可以 为此查
at the git blame for this so if I do get 看 git blame,所以如果我确实得到了
1:18:07 blame config dot yml it'll print out all the blame config dot yml,它会打印出 右列
lines kind of in the right column 中的所有行,
1:18:13 and then in the left side it'll show me 然后在左侧,它会告诉我 提交的更改是
what commits that change was made in 什么
and
1:18:17 by whom and then looking at this like I 由谁创建,然后查看这个,就像我 可以
can go down to this collections line it 进入这个集合行,它
1:18:24 was made in this commit that's the last 是在这个提交中创建的,这是 修改该行
commit that modified that line and now I 的最后一次提交,现在我

about:blank 47/52
2023/5/11 15:40 For print

1:18:29 can use the git show command to get 可以使用 git show 命令获取 该特定提交
information for that particular commit 的信息
1:18:33 oh and this is kind of useful redo lectures 哦 这是一种有用的 redo lectures 是一个
is a collection that's probably 集合,它可能
1:18:37 what was related to that collections line 与该集合 行相关,然后除了显示
and then beyond just showing the
1:18:43 commit and the commit message it also 提交和提交消息之外,它还向 我显示了
shows me the actual changes introduced
1:18:47 in that particular commit and they can go 该特定提交中引入的实际更改,他们可
look through them and understand 以查看 它们 并了解
1:18:49 what's going on another kind of cool 发生了什么另一种很酷的 命令是一个名
command is a command called git stash 为 git stash 的命令所以让我们
so
1:18:55 let's go back to our demo repository and 回到我们的演示存储库并 在这里演示如
demonstrate that here so say if some 果这里有一些
1:18:58 changes here and I temporarily want to 更改我暂时想把 它们收起来如果我确实
put them away if I do get stash it will 得到了 stash 它会
1:19:07 revert my working directory to the state it 恢复 我的工作目录恢复到 上次提交时的
was in at the last commit so if I do 状态,所以如果我执行
1:19:12 cat hollow text that change is gone but cat 空心文本,更改就消失了,但 它不只
it's not just deleted its saved 是删除它保存
1:19:16 somewhere and if I do get stash pop it 在某个地方,如果我确实得到 stash pop
will undo the stash so now if I look at 它 会撤消隐藏所以现在如果我看
1:19:22 hello text it has the changes I made so 你好文本它有我所做的更改所以 另一个
yet another useful command another 有用的命令另一个
1:19:28 really neat command is something called 非常简洁的命令是 git bisect 并且它有一
git bisect and this has a complicated 个复杂的
1:19:32 interface that we're not going to 界面我们不打算 详细演示但基本上这
demonstrate in detail but basically this
1:19:35 is a tool that can be used to solve a 是一个可以用来解决问题的工具 一堆问
bunch of problems where you need to 题,你需要
1:19:38 manually search history for something 手动搜索某些东西的历史 假设你在一个
suppose you're in a scenario where 场景中,
1:19:42 you've been working on a project for a 你已经在一个项目上工作了很 长时间,
long time you have lots and lots of 你有很多很多
1:19:45 snapshots you're a thousand commits in 快照,你有上千次提交, 然后你 请注
and then you notice that some unit test 意,某些单元测试
1:19:48 doesn't pass anymore but you know that 不再通过,但您知道 它像
this was passing like
1:19:52 year ago and you're trying to figure out at 一年前一样通过了,您正试图弄清楚 它
what point did it break like at what 是在什么时候中断的,就像在什么
1:19:56 point was this regression in your code 时候代码中 引入了这种回归,所以您可
introduced so one thing you could do is 以做一件事 做的是

about:blank 48/52
2023/5/11 15:40 For print

1:19:59 manually check out like go back one 手动检查,比如返回一个 提交,看看单


commit and see if the unit test is still 元测试是否仍然
1:20:02 failing go back one commit see if it's still 失败返回一个提交,看看它是否 仍然失
failing and eventually you'll find 败,最终你会找到
1:20:05 the first commit where the test stopped 测试停止工作的第一个提交 ,它可能会
working and it'll probably tell you like 告诉你喜欢
1:20:10 what broke but that's kind of annoying to 什么坏了但是手动 做有点烦人通过视线
do manually get by sight automates 自动执行
1:20:15 that process and it actually binary 该过程并且它实际上二进制 搜索你的历
searches your history so it does this in 史所以它以
1:20:19 the most efficient way possible and not 最有效的方式做到这一点而且 不仅 get
only that get bisect can take in a bisect 可以接受
1:20:23 scripts that it uses to try to figure out 它用来尝试的脚本 弄清楚提交的查看是
whether a committed looking at is
1:20:26 good or bad so it can be a fully 好是坏,所以它可以是一个完全 自动化
automated process like you can give git 的过程,就像你可以给 git
1:20:31 bisect a unit test and say find the first bisect 一个单元测试并说找到 这个单元
commit where this unit test 测试停止通过的第一个提交
1:20:34 stopped passing it's a really powerful tool 它是一个非常强大的 工具另一个随机的
another random thing that's kind of 东西 有用的
1:20:42 useful is something called a git ignore file 是一个叫做 git ignore 文件的东西,所以
so by default if you have random 默认情况下,如果你
1:20:47 files in a directory like let me create the 在目录中有随机文件,比如让我创建 点
dot d s underscore store file whoops d s 下划线存储文件 whoops
1:20:55 create the dot d s underscore store file 创建点 d s 下划线存储文件 ,然后执行
and then do git status so D s stores git status 这样 D s 存储
1:21:02 like some nuisance file that Mac OS 就像一些麻烦 Mac OS 创建的文件我不
creates I don't know exactly what goes 知道这里到底有什么
1:21:04 in here but basically once this file is in 但基本上一旦这个文件 在这个目录中现
this directory now whenever I do get 在每当我得到
1:21:09 status it says oh there's this new file that 状态它说哦有这个 我以前从未听说过的
I've never heard of it before but 新文件但
1:21:12 it apparently here like do you want to add 它显然在这里 就像你想 添加它一样,这
it and this sort of tough stuff gets 种棘手的事情变得
1:21:16 annoying and there's a lot of other stuff 很烦人, 除了操作系统特定的垃圾之
beyond OS specific garbage that 外,还有很多其他东西
1:21:20 might be in a directory like for example if 可能在一个目录中,例如, 如果你正在
you're working with C code you might 使用 C 代码,你可能会
1:21:24 compile it and produce dot o files or 编译它并产生点 o 文件或 可执行文件或
executable files or things like that and 类似的东西,
1:21:28 you probably don't want binaries to be 你可能不希望二进制文件成为 你提交历
part of your commit history you only 史的一部分你只
about:blank 49/52
2023/5/11 15:40 For print

1:21:31 want the source code and so git has a 想要源代码,所以 git 有一种 方法可以让
way of you being able to tell the tool 你告诉工具
1:21:37 that you don't care about a particular set 你不关心 关于一 组特定的文件并忽略它
of files and to ignore them and 们,
1:21:40 that's something called a git ignore file so 这就是所谓的 git ignore 文件,所以如果
if I go and modify the file 我去修改
1:21:44 called git ignore in the current directory I 当前目录中名为 git ignore 的文件, 我可
can specify particular file 以指定特定的文件
1:21:49 names or patterns of file names like say I 名或文件名模式,比如 我可以指定星号
can specify star dot o so any file 点 o 所以任何以
1:21:53 ending in dot o along with da store and 点 o 结尾的文件和 da store 现在如果我
now if I touch food oh and now do a get 触摸食物哦现在做一个获取
1:21:59 status I'll see that git says okay I've 状态 我会看到 git 说好的我已经
1:22:03 hollowed out tax which I've modified sure 挖空了我修改过的税
and
1:22:05 and I have get ignore so you should track 并且我有 get ignore 所以你应该 使用它
your get ignore file using it but 来跟踪你的 get ignore 文件,但请
1:22:09 notice that it doesn't mention my dot d s 注意它没有提到我的 dot d s 存储文件或
store file or my food out o file 我的 food out o 文件
1:22:15 that's present in the current directory 存在于当前目录中, 因为它已被忽略所
because that has been get ignored so 以
1:22:20 that's a quick overview of a little bit of 这是一个快速概述 一些 高级的获取功能
advanced get functionality just to 只是为了让
1:22:24 give you a flavor of what sorts of cool 您了解 这个工具可以做什么很酷的事情
things this tool can do and then finally 最后
1:22:30 we have a couple other topics that are 我们还有几个其他主题 在讲义中有更
covered in the lecture notes in more
1:22:34 detail I'll just quickly list them here so you 详细的介绍我将在这里快速列出它们 所
know what to look for one is that 以 你知道要寻找什么是
1:22:38 there are many graphical clients forget 有很多图形客户端忘记 我们不亲自使用
we don't personally use them we like the 它们我们喜欢
1:22:43 git command line tool but some of them git 命令行工具但其中一些 还不错你可能
are kind of ok and you might want to 想
1:22:47 check them out just to see if you prefer 检查它们只是为了看看你是否 更喜欢 使
using those another thing is shell 用那些,另一件事是 shell
1:22:52 integration so you've noticed that in this 集成,所以您已经注意到,在 本教程
tutorial I've done get status a 中,我已经完成了一大堆 get status
1:22:56 whole bunch to see kind of what's going 以了解 我的存储库发生了什么,这
on with my repository well that's kind
1:23:00 of annoying to do and a lot of people 很烦人,而且很多人 都有他们的 设置
have their shell prompts set up so that shell 提示,以便

about:blank 50/52
2023/5/11 15:40 For print

1:23:04 just within this shell prompt itself like on 在这个 shell 提示本身中就像 在每一行中
every line it will show me a 一样,它会向我展示
1:23:07 very succinct summary of what's going 我的存储库正在发生的事情的非常简洁
on with my repository so it might show 的摘要,因此它可能会向我展示
me a
1:23:12 summary of what branch I have currently 我当前 检出的分支的摘要以及是否可能
checked out along with maybe if I've 我已经
1:23:15 modified files or untracked files and so 修改了文件或未跟踪的文件,因此 我们
we have a link in the lecture notes on 在讲义中有一个链接,介绍
1:23:19 how to get some nice shell integration for 如何获得一些不错的 shell 集成,以便
displaying kind of get related
1:23:24 information in your shell prompt similar to 在 shell 提示符中显示某种获取相关信
that you can get integrations with 息,类似于 您可以获得与
1:23:29 your text editor so for example I use vim 文本编辑器的集成,因此 例如,我使用
and I have a plug-in for vim that vim,我有一个 vim 插件,它
1:23:35 does all sorts of interesting get related 可以做各种有趣的获取 相关的事情我可
stuff one thing I can do with 以用这个插件做的一件事
1:23:38 this plug-in is look at get blame 是查看获取责备 信息记住我们只是
information remember we just looked at
1:23:41 this through the command line instead I 通过命令行查看这个而不是我 可以使用
can look at it with this plug-in and it 这个插件查看它,它
1:23:44 lets me work with it a lot faster I can look 让我可以更快地使用它 我可以 查看
at get blame press enter when blame 将鼠标悬停在
1:23:48 hovering over a specific commit and it 特定提交上时按回车键,它向 我显示了
shows me that particular commit in my 我的
1:23:52 text editor it even hides all the other files 文本编辑器中的特定提交,它甚至隐藏
and shows me just the one file I 了所有其他提交 文件并只显示我
1:23:56 was looking at which is presumably what 正在查看的一个文件,这可能是 我关心
I care about so we have links to that in 的,所以我们在讲义中也有指向该文件
的链接,
1:24:00 the lecture notes as well and there are a -
couple of there interesting things you
1:24:05 could look at there if you're interested 如果您有兴趣,可以在那里查看一些有
finally this lecture by itself is 趣的东西 最后,这个讲座本身
1:24:11 probably not enough to teach you 可能不足以教会你 关于 git 你需要知道的
everything you need to know about git 一切
1:24:13 it's a good start we think that the right 这是一个好的开始我们认为 正确的学习
way of learning get was to learn 方式是了解
1:24:17 about the underlying data model the 底层数据模型、整个
whole
1:24:19 objects and references and how get 对象和引用以及如何获取 模型历史 然后
models history and then we gave you an 我们向您

about:blank 51/52
2023/5/11 15:40 For print

1:24:23 introduction to using the git commands 介绍了如何使用 git 命令 ,如果您想在今


and if you want to become really 天的讲义的
1:24:27 proficient at this tool in the resources 资源部分真正精通此工具,
section in the lecture notes for today
1:24:31 we have a link to a book called pro git so 我们有一本名为 pro git 的书的链接, 这
this is a free book it's nicely 是一本免费的书
1:24:35 written it's pretty short and I think going 写得很好,它很短,我认为 读完那本书
through the first couple chapters 的前几章
1:24:38 of that book should teach you basically 基本上应该教会你 所有你需要知道的东
everything you need to know in order to 西,以便
1:24:42 use get proficiently for real software 熟练地使用 get 进行真正的软件 项目并
projects and for contributing 贡献
1:24:45 it's a project on github and things like that 它是 github 上的一个项目和类似的东
and then finally just like all the 西, 然后 最后,就像所有
1:24:50 other lectures we have a number of 其他讲座一样, 如果
exercises you can go to go through if
1:24:53 you want some interesting and 你想要一些有趣且具 有挑战性的问题,
challenging problems that you can figure 你可以
1:24:57 out how to do 弄清楚如何去做,你可以通过一些练习

about:blank 52/52

You might also like