git 如何更改我分叉的 GitHub 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5749246/
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 10:42:55  来源:igfitidea点击:

How do I change which GitHub project I forked from?

gitgithubfork

提问by LanguagesNamedAfterCofee

I forked a project, made some changes, and got a pull request accepted. But now, the project I forked moved to another repository and is a fork of that repository.

我分叉了一个项目,进行了一些更改,并接受了一个拉取请求。但是现在,我分叉的项目移到了另一个存储库,并且是该存储库的一个分叉。

That is:

那是:

Original -> MyFork

Now:

现在:

NewOriginal -> Original -> MyFork

How would I get it to the following?

我将如何获得以下内容?

NewOriginal -> MyFork

采纳答案by poke

Locally you can just change the target of the original repository is located at. Usually that repository is called upstream, so you would do this:

在本地,您可以更改原始存储库所在的目标。通常该存储库称为upstream,因此您可以这样做:

git remote set-url upstream git://example.com/NewOriginal.git

Depending on what host you are using (that is, where your fork is located), there might be some additional internal links, you can't change so easily. For example on Github, the fork is directly linked to the original you forked from. In that case you need to fork the new project again, and work with the new fork.

根据您使用的主机(即您的 fork 所在的位置),可能会有一些额外的内部链接,您无法轻易更改。例如在 Github 上,分叉直接链接到您分叉的原始文件。在这种情况下,您需要再次分叉新项目,并使用新的分叉。

In that case however you can easily change the URLof the originrepository as well, and just push everything you changed before in your old fork into your new fork.

在这种情况下,但是你可以很容易地改变URL中的原产地库,以及,只是把一切都在你的老叉之前变成你的新的分支。

回答by Castrohenge

NOTE: The following solution is incomplete as you'll lose all wiki content and issues specific to your fork.

注意:以下解决方案是不完整的,因为您将丢失所有 wiki 内容和特定于您的分支的问题。

You can achieve this using the following steps:

您可以使用以下步骤实现此目的:

  1. Pull down all branches and tags from your existing fork.
  2. Delete your repository on GitHub.
  3. Fork from the new repository.
  4. Update the remote URLif necessary.
  5. Push all your local branches and tags to the new repository.
  1. 从现有分叉中拉下所有分支和标签。
  2. 删除您在 GitHub 上的存储库。
  3. 从新存储库分叉。
  4. 如有必要,更新远程URL
  5. 将所有本地分支和标签推送到新存储库。

回答by knittl

Update the remote URLin your repository:

更新存储库中的远程URL

git remote set-url origin <url to NewOriginal, e.g. git://…/bla.git>

回答by user2651178

Assuming you performed the proper forking and adding upstream see githubHelpOnFork; to just change the upstream URL, do:

假设您执行了正确的分叉并添加上游,请参阅githubHelpOnFork;要更改上游 URL,请执行以下操作:

  1. verify what your current upstream and origin looks like :

    git remote -v
    
  2. if you see upstream listed and you want just change its url, do what @poke suggested (if not follow the helpGithub link above to add a new upstream) :

    git remote set-url upstream git://example.com/NewOriginal.git
    
  3. then verify that upstream is pointing to the new URL

    git remote -v

  1. 验证您当前的上游和来源是什么样的:

    git remote -v
    
  2. 如果您看到已列出上游并且只想更改其 url,请执行 @poke 建议的操作(如果没有按照上面的 helpGithub 链接添加新的上游):

    git remote set-url upstream git://example.com/NewOriginal.git
    
  3. 然后验证上游是否指向新 URL

    git远程 -v