git branch、fork、fetch、merge、rebase 和 clone 有什么区别?

git branch、fork、fetch、merge、rebase 和 clone 有什么区别?

问题描述:

我想了解 Git 中分支、分叉和克隆的区别?

I want to understand the difference between a branch, a fork and a clone in Git?

同样,当我执行 git fetch 而不是 git pull 时,这意味着什么?

Similarly, what does it mean when I do a git fetch as opposed to a git pull?

此外,与 merge 相比,rebase 是什么意思?

Also, what does rebase mean in comparison to merge?

如何将个人提交压缩在一起?

How can I squash individual commits themselves together?

它们是如何使用的,为什么使用它们,它们代表什么?

How are they used, why are they used and what do they represent?

GitHub 是如何计算的?

How does GitHub figure in?

克隆只是存储库的副本.从表面上看,它的结果等同于 svn checkout,您可以在其中从其他存储库下载源代码.像 Subversion 这样的集中式 VCS 和像 Git 这样的 DVCS 之间的区别在于,在 Git 中,当您克隆时,您实际上是在复制整个源存储库,包括所有历史记录和分支.您现在在您的机器上有一个新的存储库,您所做的任何提交都会进入该存储库.在您将这些提交推送到另一个存储库(或原始存储库)或有人从您的存储库中提取提交(如果它是可公开访问的)之前,没有人会看到任何更改.

A clone is simply a copy of a repository. On the surface, its result is equivalent to svn checkout, where you download source code from some other repository. The difference between centralized VCS like Subversion and DVCSs like Git is that in Git, when you clone, you are actually copying the entire source repository, including all the history and branches. You now have a new repository on your machine and any commits you make go into that repository. Nobody will see any changes until you push those commits to another repository (or the original one) or until someone pulls commits from your repository, if it is publicly accessible.

分支是存储库中的东西.从概念上讲,它代表了一条发展线索.您通常有一个 master 分支,但您也可能有一个分支,您正在其中处理某些功能 xyz,以及另一个修复错误 abc 的分支.当您签出一个分支时,您所做的任何提交都将保留在该分支上,并且不会与其他分支共享,直到您将它们与相关分支合并或将它们重新绑定到相关分支上.当然,当涉及到分支时,Git 似乎有点奇怪,直到您查看分支实现方式的底层模型.与其自己解释(我已经说得太多了,我想),我将链接到 Git 网站上关于 Git 如何建模分支和提交的计算机科学"解释:

A branch is something that is within a repository. Conceptually, it represents a thread of development. You usually have a master branch, but you may also have a branch where you are working on some feature xyz, and another one to fix bug abc. When you have checked out a branch, any commits you make will stay on that branch and not be shared with other branches until you merge them with or rebase them onto the branch in question. Of course, Git seems a little weird when it comes to branches until you look at the underlying model of how branches are implemented. Rather than explain it myself (I've already said too much, methinks), I'll link to the "computer science" explanation of how Git models branches and commits, taken from the Git website:

http://eagain.net/articles/git-for-computer-scientists/

分叉实际上并不是一个 Git 概念,它更像是一个政治/社会理念.也就是说,如果有些人对项目的进展方式不满意,他们可以获取源代码,并与原始开发人员分开处理.那将被视为分叉.Git 使分叉变得容易,因为每个人都已经拥有自己的源代码主"副本,因此就像切断与原始项目开发人员的联系一样简单,并且不需要像使用 SVN 那样从共享存储库中导出历史记录.

A fork isn't a Git concept really, it's more a political/social idea. That is, if some people aren't happy with the way a project is going, they can take the source code and work on it themselves separate from the original developers. That would be considered a fork. Git makes forking easy because everyone already has their own "master" copy of the source code, so it's as simple as cutting ties with the original project developers and doesn't require exporting history from a shared repository like you might have to do with SVN.

由于我不知道 GitHub 等网站使用的fork"的现代定义,请查看评论以及 Michael Durrant 的回答 在我的下方以获取更多信息.

since I was not aware of the modern definition of "fork" as used by sites such as GitHub, please take a look at the comments and also Michael Durrant's answer below mine for more information.