git GitHub 上的 Forking 和 Cloning 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7057194/
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
What is the difference between Forking and Cloning on GitHub?
提问by Steve Dunn
I'd like to know the differences between doing a Fork of a project and doing a clone
of it.
我想知道做一个项目的一个叉子和做一个项目之间的区别clone
。
Can I only send pull requests via GitHub if I've forked a project?
如果我已经分叉了一个项目,我可以只通过 GitHub 发送拉取请求吗?
采纳答案by michel-slm
Basically, yes. A fork
is just a request for GitHub to clone the project and registers it under your username; GitHub also keeps track of the relationship between the two repositories, so you can visualize the commits and pulls between the two projects (and other forks).
基本上,是的。Afork
只是请求 GitHub 克隆项目并在您的用户名下注册;GitHub 还跟踪两个存储库之间的关系,因此您可以可视化两个项目(和其他分支)之间的提交和拉取。
You can still request that people pull from your cloned repository, even if you don't use fork
-- but you'd have to deal with making it publicly available yourself. Or send the developers patches (see git format-patch
) that they can apply to their trees.
您仍然可以请求人们从您的克隆存储库中提取,即使您不使用fork
- 但您必须自己处理使其公开可用。或者向开发人员发送补丁(请参阅 参考资料git format-patch
),他们可以应用到他们的树上。
回答by Aniket Thakur
When you say you are Forkinga repository you are basically creating a copy of the repository under your GitHub ID. The main point to note here is that any changes made to the original repository will be reflected back to your forkedrepositories(you need to fetch and rebase). However, if you make any changes to your forkedrepository you will have to explicitly create a pull request to the originalrepository. If your pull request is approved by the administrator of the original repository, then your changes will be committed/merged with the existing originalcode-base. Until then, your changes will be reflected only in the copy you forked.
当您说要分叉存储库时,您基本上是在您的 GitHub ID 下创建存储库的副本。这里要注意的要点是,对原始存储库所做的任何更改都将反映回您的分叉存储库(您需要获取和变基)。但是,如果您对分叉存储库进行任何更改,则必须明确创建对原始存储库的拉取请求。如果您的拉取请求被原始存储库的管理员批准,那么您的更改将与现有的原始代码库提交/合并。在此之前,您的更改将仅反映在您分叉的副本中。
In short:
简而言之:
The Fork & Pull Model lets anyone fork an existing repository and push changes to their personal fork without requiring access be granted to the source repository. The changes must then be pulled into the source repository by the project maintainer.
Fork & Pull 模型允许任何人 fork 现有存储库并将更改推送到他们的个人 fork,而无需授予对源存储库的访问权限。然后必须由项目维护者将更改拉入源存储库。
Note that after forking you can clone your repository (the one under your name) locally on your machine. Make changes in it and push it to your forked repository. However, to reflect your changes in the original repository your pull request must be approved.
请注意,在 fork 之后,您可以在您的机器上本地克隆您的存储库(您名下的存储库)。对其进行更改并将其推送到您的分叉存储库。但是,要在原始存储库中反映您的更改,您的拉取请求必须得到批准。
Couple of other interesting dicussions -
一些其他有趣的讨论 -
Are git forks actually git clones?
回答by Alisa
- Forked project is on your online repository (repo).
- Cloned project is on your local machine (I usually clone after forking the repo).
- Forked 项目位于您的在线存储库 (repo) 上。
- 克隆的项目在你的本地机器上(我通常在分叉 repo 后克隆)。
You can commit on your online repo (or commit on your local repo and then push to your online repo), then send pull request.
您可以提交在线存储库(或提交本地存储库,然后推送到您的在线存储库),然后发送拉取请求。
Project manager can accept it to get your changes in his main online version.
项目经理可以接受它以在他的主要在线版本中获取您的更改。
回答by Philip Oakley
A clone is where you have proper duplication, and separation between, two (possibly different) versions of a repository. When one repo is amended, the new content must be actively copied to the other repo using a push command. And changes in the other repo fetched.
克隆是您在存储库的两个(可能不同)版本之间进行适当复制和分离的地方。当修改一个 repo 时,必须使用 push 命令将新内容主动复制到另一个 repo。并获取了其他 repo 中的更改。
When you fork a repo, on a server, there is no need for duplication of content because both repos will use the same [fixed object] content from that same server. The 'trick' is in managing the different user viewpoints so that each user believes they have a full personal copy of the repo. Pushes and fetches between forks is simply updates the user's pointers.
当您在服务器上 fork 一个 repo 时,不需要复制内容,因为两个 repos 将使用来自同一服务器的相同 [fixed object] 内容。“技巧”在于管理不同的用户观点,以便每个用户相信他们拥有完整的个人副本。分叉之间的推送和获取只是更新用户的指针。
At a lower level, git does the same thing internally. If you have three different files, each containing Hello World
, then git simply 'forks' its single copy of the Hello World blob and offers it up in each of the three places as required.
在较低级别,git 在内部做同样的事情。如果您有三个不同的文件,每个文件都包含Hello World
,那么 git 只需“分叉”它的 Hello World blob 的单个副本,并根据需要在三个位置中的每个位置提供它。
The ability to fork on the server means that Github's large storage allowance isn't that big on average as every body shares the one single underlying repo.
在服务器上分叉的能力意味着 Github 的大存储容量平均来说并不是那么大,因为每个机构都共享一个单一的底层存储库。
回答by Farhan Haque
In a nutshell, Forking is perhaps the same as "cloning under your GitHub ID/profile". A fork is anytime better than a clone, with a few exceptions, obviously. The forked repository is always being monitored/compared with the original repository unlike a cloned repository. That enables you to track the changes, initiate pull requests and also manually sync the changes made in the original repository with your forked one.
简而言之,Forking 可能与“在您的 GitHub ID/profile 下克隆”相同。显然,除了少数例外,分叉总是比克隆好。与克隆存储库不同,分叉存储库始终与原始存储库进行监视/比较。这使您能够跟踪更改,启动拉取请求,还可以手动将原始存储库中所做的更改与分叉的存储库同步。
回答by Theodore Norvell
While @AniketThakur's answer is very good. No one has answered the following question yet.
虽然@AniketThakur 的回答非常好。还没有人回答以下问题。
Can I only send pull requests via GitHub if I've forked a project?
如果我已经分叉了一个项目,我可以只通过 GitHub 发送拉取请求吗?
No. If you are a contributor to a repository, you can: Make a local clone. Make a local branch. Add commits to that branch. Push the local branch back to github (creating a remote branch in the process). Make a pull request requesting for that branch to be merged into the master branch (or whatever branch you like).
不可以。如果您是存储库的贡献者,您可以: 制作本地克隆。做一个本地分支。将提交添加到该分支。将本地分支推回 github(在此过程中创建远程分支)。发出请求请求将该分支合并到主分支(或您喜欢的任何分支)。
回答by Princess Ruthie
In case you did what the questioner hinted at (forgot to fork and just locally cloned a repo, made changes and now need to issue a pull request) you can get back on track:
如果你做了提问者暗示的事情(忘记分叉,只是在本地克隆了一个仓库,做了更改,现在需要发出拉取请求),你可以回到正轨:
- fork the repo you want to send pull request to
- push your local changes to your remote
- issue pull request
- 分叉您要向其发送拉取请求的存储库
- 将您的本地更改推送到您的遥控器
- 发出拉取请求
回答by BJennings
Another weird subtle difference on GitHub is that changes to forks are not counted in your activity log until your changes are pulled into the original repo. What's more, to change a fork into a proper clone, you have to contact Github support, apparently.
GitHub 上另一个奇怪的细微差别是,在您的更改被拉入原始存储库之前,对分叉的更改不会计入您的活动日志。更重要的是,要将 fork 更改为适当的克隆,显然您必须联系 Github 支持。
From Why are my contributions not showing up:
Commit was made in a fork
Commits made in a fork will not count toward your contributions. To make them count, you must do one of the following:
Open a pull requestto have your changes merged into the parent repository. To detach the fork and turn it into a standalone repository on GitHub, contact GitHub Support. If the fork has forks of its own, let support know if the forks should move with your repository into a new network or remain in the current network. For more information, see "About forks."
提交是在一个叉子中完成的
在分叉中进行的提交不会计入您的贡献。要使它们计数,您必须执行以下操作之一:
打开拉取请求以将您的更改合并到父存储库中。要分离 fork 并将其转换为 GitHub 上的独立存储库,请联系GitHub 支持。如果分叉有自己的分叉,请让支持人员知道分叉是否应该与您的存储库一起移动到新网络中或保留在当前网络中。有关更多信息,请参阅“关于分叉”。
回答by Testilla
In a nutshell, "fork" creates a copy of the project hosted on your own GitHub account.
简而言之,“fork”会创建一个托管在您自己的 GitHub 帐户上的项目副本。
"Clone" uses git software on your computer to download the source code and it's entire version history unto that computer
“克隆”使用您计算机上的 git 软件下载源代码及其整个版本历史记录到该计算机