Lecture6 - Version Control (Git)
Lecture6 - Version Control (Git)
about:blank 1/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
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
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
about:blank 10/52
2023/5/11 15:40 For print
about:blank 11/52
2023/5/11 15:40 For print
about:blank 12/52
2023/5/11 15:40 For print
about:blank 13/52
2023/5/11 15:40 For print
about:blank 14/52
2023/5/11 15:40 For print
about:blank 15/52
2023/5/11 15:40 For print
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: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
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 来帮助你,
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
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
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
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
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
about:blank 34/52
2023/5/11 15:40 For print
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
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
about:blank 42/52
2023/5/11 15:40 For print
about:blank 43/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
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: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
about:blank 52/52