Git 分叉实际上是 Git 克隆吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6286571/
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
Are Git forks actually Git clones?
提问by Brian
I keep hearing people say they're forking code in Git. Git "fork" sounds suspiciously like Git "clone" plus some (meaningless) psychological willingness to forgo future merges. There is no fork command in Git, right?
我一直听到人们说他们在 Git 中分叉代码。Git“fork”听起来很可疑,就像 Git“clone”加上一些(无意义的)心理愿意放弃未来的合并。Git 中没有 fork 命令,对吧?
GitHub makes forks a little more real by stapling correspondence onto it. That is, you press the fork button and later, when you press the pull request button, the system is smart enough to email the owner. Hence, it's a little bit of a dance around repository ownership and permissions.
GitHub 通过将信件装订到分叉上,使分叉更加真实。也就是说,您按下分叉按钮,然后当您按下拉取请求按钮时,系统足够智能,可以向所有者发送电子邮件。因此,它有点像围绕存储库所有权和权限的舞蹈。
Yes/No? Any angst over GitHub extending Git in this direction? Or any rumors of Git absorbing the functionality?
是/否?对 GitHub 朝这个方向扩展 Git 有任何焦虑吗?或者任何关于 Git 吸收功能的传言?
回答by VonC
Fork, in the GitHub context, doesn't extend Git.
It only allows clone on the server side.
Fork,在 GitHub 上下文中,不扩展 Git。
它只允许在服务器端进行克隆。
When you clone a GitHub repository on your local workstation, you cannot contribute back to the upstream repository unless you are explicitly declared as "contributor". That's because your clone is a separate instance of that project. If you want to contribute to the project, you can use forking to do it, in the following way:
当您在本地工作站上克隆 GitHub 存储库时,除非您明确声明为“贡献者”,否则您无法回馈上游存储库。那是因为您的克隆是该项目的一个单独实例。如果你想为项目做贡献,你可以使用 forking 来做,方法如下:
- clone that GitHub repository on your GitHub account (that is the "fork" part, a clone on the server side)
- contribute commits to that GitHub repository (it is in your own GitHub account, so you have every right to push to it)
- signal any interesting contribution back to the original GitHub repository (that is the "pull request" partby way of the changes you made on your own GitHub repository)
- 在您的 GitHub 帐户上克隆该 GitHub 存储库(即“fork”部分,服务器端的克隆)
- 向该 GitHub 存储库贡献提交(它在您自己的 GitHub 帐户中,因此您有权推送到它)
- 将任何有趣的贡献发送回原始 GitHub 存储库(即通过您在自己的 GitHub 存储库上所做的更改的“拉取请求”部分)
Check also "Collaborative GitHub Workflow".
另请查看“协作 GitHub 工作流程”。
If you want to keep a link with the original repository (also called upstream), you need to add a remote referring that original repository.
See "What is the difference between origin and upstream on GitHub?"
如果要保持与原始存储库(也称为上游)的链接,则需要添加引用该原始存储库的远程。
请参阅“ GitHub 上的 origin 和 upstream 有什么区别?”
And with Git 2.20 (Q4 2018) and more, fetching from fork is more efficient, with delta islands.
使用 Git 2.20(2018 年第 4 季度)等版本,从 fork 获取更高效,使用delta island。
回答by meagar
I keep hearing people say they're forking code in git. Git "fork" sounds suspiciously like git "clone" plus some (meaningless) psychological willingness to forgo future merges. There is no fork command in git, right?
我一直听到人们说他们在 git 中分叉代码。Git“fork”听起来很可疑,就像 git“clone”加上一些(无意义的)放弃未来合并的心理意愿。git 中没有 fork 命令,对吧?
"Forking" is a concept, not a command specifically supported by any version control system.
“分叉”是一个概念,不是任何版本控制系统特别支持的命令。
The simplest kind of forking is synonymous with branching. Every time you create a branch, regardless of your VCS, you've "forked". These forks are usually pretty easy to merge back together.
最简单的分叉是分支的同义词。每次创建分支时,无论您使用什么 VCS,都已经“分叉”了。这些分叉通常很容易合并在一起。
The kind of fork you're talking about, where a separate party takes a complete copy of the code and walks away, necessarily happens outside the VCS in a centralized system like Subversion. A distributed VCS like Git has much better support for forking the entire codebase and effectively starting a new project.
您所谈论的那种分叉,其中一个单独的一方获取完整的代码副本并走开,必然发生在 VCS 之外的集中式系统(如 Subversion)中。像 Git 这样的分布式 VCS 对分叉整个代码库和有效启动新项目有更好的支持。
Git (not GitHub) natively supports "forking" an entire repo (ie, cloning it) in a couple of ways:
Git(不是 GitHub)本身支持通过以下几种方式“分叉”整个存储库(即克隆它):
- when you clone, a remote called
origin
is created for you - by default all the branches in the clone will track their
origin
equivalents - fetching and merging changes from the original project you forked from is trivially easy
- 当您克隆时,
origin
会为您创建一个远程调用 - 默认情况下,克隆中的所有分支都将跟踪它们的
origin
等效项 - 从您分叉的原始项目中获取和合并更改非常简单
Git makes contributing changes back to the source of the fork as simple as asking someone from the original project to pull from you, or requesting write access to push changes back yourself. This is the part that GitHub makes easier, and standardizes.
Git 使将更改贡献回 fork 的源就像要求原始项目中的某个人从您那里拉取更改一样简单,或者请求写访问权限以将更改推回自己。这是 GitHub 简化和标准化的部分。
Any angst over Github extending git in this direction? Or any rumors of git absorbing the functionality?
对 Github 向这个方向扩展 git 有任何焦虑吗?或者任何关于 git 吸收功能的谣言?
There is no angst because your assumption is wrong. GitHub "extends" the forking functionality of Git with a nice GUI and a standardized way of issuing pull requests, but it doesn't addthe functionality to Git. The concept of full-repo-forking is baked right into distributed version control at a fundamental level. You could abandon GitHub at any point and still continue to push/pull projects you've "forked".
没有焦虑,因为你的假设是错误的。GitHub 通过漂亮的 GUI 和发出拉取请求的标准化方式“扩展”了 Git 的分叉功能,但它没有将功能添加到 Git。Full-repo-forking 的概念从根本上融入了分布式版本控制。你可以在任何时候放弃 GitHub,仍然继续推/拉你已经“分叉”的项目。
回答by ssapkota
Yes, fork is a clone. It emerged because, you cannot push to others' copies without their permission. They make a copyof it for you (fork), where you will have write permission as well.
是的,fork 是一个克隆。它的出现是因为,未经他人许可,您不能推送到他人的副本。他们为您制作了一份副本(fork),您也将拥有写入权限。
In the future if the actual owner or others users with a fork like your changes they can pull it back to their own repository. Alternatively you can send them a "pull-request".
将来,如果实际所有者或其他用户喜欢您的更改,他们可以将其拉回自己的存储库。或者,您可以向他们发送“拉取请求”。
回答by Daenyth
"Fork" in this context means "Make a copy of their code so that I can add my own modifications". There's not much else to say. Every clone is essentially a fork, and it's up to the original to decide whether to pull the changes from the fork.
在这种情况下,“分叉”的意思是“复制他们的代码,以便我可以添加自己的修改”。没有什么可说的。每个克隆本质上都是一个分叉,由原先决定是否从分叉中提取更改。
回答by Sam Johnson
Cloning involves making a copy of the git repository to a local machine, while forking is cloning the repository into another repository. Cloning is for personal use only (although future merges may occur), but with forking you are copying and opening a new possible project path
克隆涉及将 git 存储库的副本复制到本地计算机,而分叉则是将存储库克隆到另一个存储库中。克隆仅供个人使用(尽管未来可能会发生合并),但通过分叉,您正在复制并打开一个新的可能的项目路径
回答by aliasav
Forking is done when you decide to contribute to some project. You would make a copy of the entire project along with its history logs. This copy is made entirely in your repository and once you make these changes, you issue a pull request. Now its up-to the owner of the source to accept your pull request and incorporate the changes into the original code.
当您决定为某个项目做出贡献时,分叉就完成了。您将制作整个项目及其历史记录的副本。此副本完全在您的存储库中制作,一旦您进行这些更改,您就会发出拉取请求。现在由源的所有者来接受您的拉取请求并将更改合并到原始代码中。
Git clone is an actual command that allows users to get a copy of the source. git clone [URL] This should create a copy of [URL] in your own local repository.
Git clone 是一个实际的命令,允许用户获取源的副本。git clone [URL] 这应该在您自己的本地存储库中创建 [URL] 的副本。
回答by Daniel Shen
I think fork is a copy of other repository but with your account modification. for example, if you directly clone other repository locally, the remote object origin is still using the account who you clone from. You can't commit and contribute your code. It is just a pure copy of codes. Otherwise, If you fork a repository, it will clone the repo with the update of your account setting in you github account. And then cloning the repo in the context of your account, you can commit your codes.
我认为 fork 是其他存储库的副本,但您的帐户已修改。例如,如果您直接在本地克隆其他存储库,则远程对象源仍在使用您从中克隆的帐户。你不能提交和贡献你的代码。它只是代码的纯粹副本。否则,如果您 fork 存储库,它将使用您在 github 帐户中的帐户设置的更新来克隆存储库。然后在您的帐户上下文中克隆存储库,您可以提交代码。
回答by Hugh
There is a misunderstanding here with respect to what a "fork" is. A fork is in fact nothing more than a set of per-user branches. When you push to a fork you actually do push to the original repository, because that is the ONLY repository.
关于“分叉”是什么,这里有一个误解。分叉实际上只不过是一组每个用户的分支。当您推送到分叉时,您实际上是推送到原始存储库,因为这是唯一的存储库。
You can try this out by pushing to a fork, noting the commit and then going to the original repository and using the commit ID, you'll see that the commit is "in" the original repository.
您可以通过推送到 fork 来尝试这个,注意提交,然后转到原始存储库并使用提交 ID,您将看到提交“在”原始存储库中。
This makes a lot of sense, but it is far from obvious (I only discovered this accidentally recently).
这很有意义,但远非显而易见(我最近才偶然发现了这一点)。
When John forks repository SuperProject what seems to actually happen is that all branches in the source repository are replicated with a name like "John.master", "John.new_gui_project", etc.
当 John 分叉存储库 SuperProject 时,似乎实际发生的是源存储库中的所有分支都以“John.master”、“John.new_gui_project”等名称进行复制。
GitHub "hides" the "John." from us and gives us the illusion we have our own "copy" of the repository on GitHub, but we don't and nor is one even needed.
GitHub“隐藏”了“约翰”。来自我们并给我们一种错觉,我们在 GitHub 上拥有自己的存储库“副本”,但我们没有,甚至也不需要。
So my fork's branch "master" is actually named "Korporal.master", but the GitHub UI never reveals this, showing me only "master".
所以我的 fork 的分支“master”实际上被命名为“Korporal.master”,但 GitHub UI 从未显示这一点,只显示我“master”。
This is pretty much what I think goes on under the hood anyway based on stuff I've been doing recently and when you ponder it, is very good design.
根据我最近一直在做的事情,这几乎是我认为在引擎盖下发生的事情,当您考虑它时,这是非常好的设计。
For this reason I think it would be very easy for Microsoft to implement Git forks in their Visual Studio Team Services offering.
出于这个原因,我认为 Microsoft 在其 Visual Studio Team Services 产品中实施 Git 分支会非常容易。
回答by Deepak G M
Apart from the fact that cloning is from server to your machine and forking is making a copy on the server itself, an important difference is that when we clone, we actually get all the branches, labels, etc.
除了克隆是从服务器到您的机器并且分叉是在服务器本身上进行复制之外,一个重要的区别是,当我们克隆时,我们实际上获得了所有分支、标签等。
But when we fork, we actually only get the current files in the master branch, nothing other than that. This means we don't get the other branches, etc.
但是当我们fork的时候,我们实际上只得到了master分支中的当前文件,除此之外别无他物。这意味着我们没有得到其他分支等。
Hence if you have to merge something back to the original repository, it is a inter-repository merge and will definitely need higher privileges.
因此,如果您必须将某些内容合并回原始存储库,则它是存储库间合并,并且肯定需要更高的权限。
Fork is not a command in Git; it is just a concept which GitHub implements. Remember Git was designed to work in peer-to-peer environment without the need to synchronize stuff with any master copy. The server is just another peer, but we look at it as a master copy.
Fork 不是 Git 中的命令;这只是 GitHub 实现的一个概念。请记住,Git 旨在在点对点环境中工作,而无需将内容与任何主副本同步。服务器只是另一个对等点,但我们将其视为主副本。
回答by anoNewb
In simplest terms,
简单来说,
When you say you are forkinga repository, you are basically creating a copy of the original repository under your GitHub ID in your GitHub account.
当您说要分叉存储库时,您基本上是在您的 GitHub 帐户中的 GitHub ID 下创建原始存储库的副本。
and
和
When you say you are cloninga repository, you are creating a local copy of the original repository in your system (PC/laptop) directly without having a copy in your GitHub account.
当您说要克隆存储库时,您是在您的系统(PC/笔记本电脑)中直接创建原始存储库的本地副本,而您的 GitHub 帐户中没有副本。