简体   繁体   English

将git repo从源代码合并到上游存储库

[英]Merging a git repo from the origin to the upstream repository

Let's say I have an upstream repository, which I have forked to a new origin . 假设我有一个upstream存储库,我将其分配到一个新的origin

If I want to merge changes from the upstream repo into my forked origin, I would do something like this from within the fork: 如果我想将上游repo中的更改合并到我的forked源中,我会在fork中执行类似的操作:

$ git merge upstream/master

How would I go the other direction, from origin to upstream? 从原点到上游,我将如何走向另一个方向? Say I change something in the fork that I want to push to the parent — how would I go about that? 假设我在fork中改变了一些我想要推送给父母的东西 - 我该怎么做呢?

Is it just a matter of setting a new remote/upstream for the parent, using the fork as the parent's upstream ? 是否只是为父设置一个新的远程/上游问题,使用fork作为父进程的upstream

A fork is simply another clone of the original repository. fork只是原始存储库的另一个克隆。

If you want to share commits/branches between them, add both of them as remote s of your local repository, and then you can decide how to merge and push your commits to which repository. 如果要在它们之间共享提交/分支,请将它们作为本地存储库的remote s添加,然后您可以决定如何合并并将提交推送到哪个存储库。

When you do git merge upstream/master , you join your current one with the master branch of your upstream remote. 当你执行git merge upstream/master ,你将当前的一个与upstream远程的master分支连接起来。 If you push those changes to upstream ( git push upstream master ), you'll update your upstream remote. 如果push这些更改push送到上游( git push upstream master ),您将更新upstream远程。 If you push them to your origin remote ( git push origin master ), you'll be updating your original repository. 如果push它们push送到origin远程( git push origin master ),您将更新原始存储库。

The only difference between a fork and a clone is about access . fork和clone之间的唯一区别是访问

If you clone some open-source project, you usually do a fork , as you can't push back into the central repository of that project, because you dont have the rights to do so. 如果你克隆一些开源项目,你通常会做一个分叉 ,因为你不能回到该项目的中央存储库,因为你没有这样做的权利。 If everybody did have the right to push something into a project's central repo, a huge amount of spam would be pushed to popular projects (not to mention the people creating a more hidden spam, eg bad quality code, viruses, whatever). 如果每个人都有权将某些内容推送到项目的核心仓库中,那么大量的垃圾邮件将被推送到热门项目中(更不用说人们创建更隐蔽的垃圾邮件,例如质量差的代码,病毒等)。

In such a case, your only chance to get code back into the central repo is, to tell the projects maintainer to pull your code. 在这种情况下,将代码重新放回中央仓库的唯一机会是告诉项目维护者提取代码。 He will review your code, and he thinks it is good, it will get merged into the central repo eventually. 他会检查你的代码,他认为这很好,最终会合并到中央仓库。 This is what is called a pull request . 这就是所谓的拉取请求

HOWEVER 然而

If you clone your own project, or the project you work on (you are the maintainer, or one of them), you have the rights to push into the central repo. 如果您克隆自己的项目或您正在处理的项目(您是维护者或其中之一),您有权进入中央仓库。 So, in that case you just can push. 所以,在这种情况下,你可以推动。 If you don't work on open-source, you will usually have this case. 如果您不使用开源,通常会遇到这种情况。 Just set up the central repo as remote and push to it. 只需将中央仓库设置为远程并推送即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM