这些词在 Git 中是什么意思:Repository、fork、branch、clone、track?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2916849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:26:40  来源:igfitidea点击:

What do these words mean in Git: Repository, fork, branch, clone, track?

gitbranchclone

提问by Eric Anderson

I'm honestly not clear on the semantics here. They're all about copies/variants of a code+history unit, but past that I'm not sure I could say. Is this logical structure explained somewhere?

老实说,我不清楚这里的语义。它们都是关于代码+历史单元的副本/变体,但过去我不确定我能说。这个逻辑结构在某处解释过吗?

回答by nfm

A repository is simply a place where the history of your work is stored. It often lives in a .gitsubdirectory of your working copy - a copy of the most recent state of the files you're working on.

存储库只是一个存储工作历史的地方。它通常位于.git您的工作副本的子目录中 - 您正在处理的文件的最新状态的副本。

To fork a project (take the source from someone's repository at certain point in time, and apply your own diverging changes to it), you would clone the remote repository to create a copy of it, then do your own work in your local repository and commit changes.

要 fork 一个项目(在某个时间点从某人的存储库中获取源代码,并对其应用您自己的不同更改),您将克隆远程存储库以创建它的副本,然后在本地存储库中完成自己的工作并提交更改。

Within a repository you have branches, which are effectively forks within your own repository. Your branches will have an ancestor commit in your repository, and will diverge from that commit with your changes. You can later merge your branch changes. Branches let you work on multiple disparate features at once.

在存储库中,您有分支,它们实际上是您自己存储库中的分支。您的分支将在您的存储库中有一个祖先提交,并且会随着您的更改而与该提交不同。您可以稍后合并您的分支更改。分支让您可以同时处理多个不同的功能。

You can also track individual branches in remote repositories. This allows you to pull in changes from another individual's branches and to merge them into a branch of your own. This may be useful if you and a friend are working on a new feature together.

您还可以跟踪远程存储库中的各个分支。这允许您从另一个人的分支中提取更改并将它们合并到您自己的分支中。如果您和朋友正在共同开发新功能,这可能会很有用。

There are lots of great git books online. Have a look at ProGitand Git Magicto get started, as well as the official tutorials and community book.

网上有很多很棒的 git 书籍。查看ProGitGit Magic以开始使用,以及官方教程和社区书籍。

回答by Eric Anderson

I'm going to answer my own question with an RTFM.

我将用 RTFM 回答我自己的问题。

But, read thisfine manual. As the author puts it:

但是,请阅读这本精美的手册。正如作者所说:

“The conclusion I draw from this is that you can only really use Git if you understand how Git works. Merely memorizing which commands you should run at what times will work in the short run, but it's only a matter of time before you get stuck or, worse, break something.

“Half of the existing resources on Git, unfortunately, take just that approach: they walk you through which commands to run when, and expect that you should do fine if you just mimic those commands. The other half does go through all the concepts, but from what I have seen, they explain Git in a manner that assumes you already understand how Git works.”

“我由此得出的结论是,只有了解 Git 的工作原理,才能真正使用 Git。仅仅记住你应该在什么时间运行哪些命令在短期内会起作用,但是你陷入困境或者更糟糕的是破坏某些东西只是时间问题。

“不幸的是,Git 上现有的一半资源都采用了这种方法:它们会引导您了解何时运行哪些命令,并期望如果您只是模仿这些命令,您应该会做得很好。另一半确实介绍了所有概念,但根据我所见,他们以一种假设您已经了解 Git 工作原理的方式来解释 Git。”

回答by Matt

This GoogleTechTalkis a fantastic introduction to Git to learn what is actually happening behind the scenes while learning the language also. It was given by a very early contributor to Git and he gave this talk in 2007 as a way of introduction into Git. If you watch this talk you will not only know what each word is, like repository, fork, branch, etc., but you will also know what is occurring behind the scenes when each of these are made, merged, etc.

这个 GoogleTechTalk是对 Git 的精彩介绍,可以在学习这门语言的同时了解幕后实际发生的事情。它是由 Git 的一位非常早期的贡献者提供的,他在 2007 年进行了这次演讲,作为对 Git 的一种介绍。如果你观看这个演讲,你不仅会知道每个词是什么,比如 repository、fork、branch 等,而且你还会知道当每个词被制作、合并等时,幕后发生了什么。

The address is long but very informative. It also contrasts Git to other Version Control Systems so you get insight into why Git was created the way it was and what the comparative advantages of it are over other control systems. Even though the talk is old it is very helpful to get up and running. I would watch this before I jumped into the manuals. Things will make much more sense as a result, I believe.

地址很长,但信息量很大。它还将 Git 与其他版本控制系统进行了对比,因此您可以深入了解 Git 的创建方式以及与其他控制系统相比的优势。即使这个谈话很老,但它对启动和运行非常有帮助。在我跳入手册之前,我会看这个。我相信,事情会因此变得更有意义。