如何同步一个分叉的存储库,因此它具有与原始存储库相同的状态?

发布于 2025-01-30 09:27:04 字数 811 浏览 3 评论 0原文

我确实使用API​​创建了GitHub存储库的叉子。现在,有一段时间后,叉子和原始存储库不超出同步。

如何使用API​​或命令行GIT命令将叉子与原始存储库同步到相同的状态?

我试图删除叉子存储库,但我没有删除它的权利。

重新铺设原始存储库也似乎也不起作用,我会

7 commits behind owner:master.

在UI中像可见的那样传达信息。

还有其他想法吗?


我尝试了此页面但它不起作用。我有很多冲突。

只是要清楚:我不想合并任何东西。我想将原始存储库同步与分叉的存储库同步,因此分叉的存储库具有与原始存储库相同的状态(历史,投入等)。我不想合并任何东西,我想同步它。

就像在编程语言中一样,当您拥有Python dictionary mydict时,它有一些数据,您只想用其他python dict替换其内容,您只会

mydict = other_dict

获得任何合并,通过将变量分配给某些内容来冲突。

我希望现在更清楚。


问题是我无法直接访问GitHub GUI,否则我只能删除叉子并再次从原始叉子叉。但这不起作用。我也没有使用API​​删除叉子的权利。

I did create a fork of a github repository using the API. Now after some while the fork and the original repository are out of sync.

How can I sync the fork to the same state as the original repository using the API or command line git commands?

I tried to remove the forked repository but I do not have the rights to remove it.

Re-forking the original repository also does not seem to work, I will have the message like

7 commits behind owner:master.

in the UI visible.

Any other idea?


I tried the solution #2 from this page but it did not work. I got many conflicts.

Just to be clear: I do not want to MERGE anything. I want to SYNC synchronize) the original repository with the forked repo, so the forked repo has the same state (history, commits, etc.) as the original repository. I do not want to merge anything, I want to SYNCHRONIZE it.

It is like in a programming language, when you have a python dictionary mydict which has some data and you want to just replace its content with a different python dict, you just do

mydict = other_dict

you also never get any "merge conflicts" by assigning the variable to some content.

I hope this is clearer now.


The problem is that I do not have direct access to the github GUI, otherwise I could just delete the fork and fork it again from the origin. But this does not work. I also do not have the rights to delete the fork using the API.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2025-02-06 09:27:04

如何使用API​​或命令行Git命令同步[GitHub]叉与原始存储库相同的状态?

我不知道gh是否有任何要做的事情,但是从命令行Git,您可以通过git克隆的组合合理地接近 - mirrorgit推动 - mirror将它们非常小心用作git push-mirror可能非常具有破坏性:

  1. run git克隆 - mirror ointer-repository-url创建原始存储库的镜面克隆。此克隆仅用于步骤2,然后丢弃。
  2. 运行git推动-Mirror fork-Repository-url以擦除叉子的当前状态并按下全新状态。
  3. 可选:删除镜面克隆以防止发生事故。

我实际上并未使用GitHub尝试过此操作,您可能会收到有关refs/pull/引用的警告,甚至在步骤2中引用

  • 。 > git for-each-ref -format =“ git update-ref-d%(refname)” ref/pull | sh

您可能希望在没有|的情况下运行此操作。 sh首先,要确保它生成正确的git update -ref -d命令。这简单地 deletes 所有refs/pull/来自镜面克隆的名称,因此git push -mirror 不会尝试推动它们。

How can I sync [a GitHub] fork to the same state as the original repository using the API or command line git commands?

I don't know if gh has anything to do it, but from command-line Git you can get reasonably close with a combination of git clone --mirror and git push --mirror. Use these with great care as git push --mirror can be quite destructive:

  1. Run git clone --mirror original-repository-URL to create a mirror clone of the original repository. This clone is only to be used for step 2, and then discarded.
  2. Run git push --mirror fork-repository-URL to wipe out the current state of the fork and push all-new state.
  3. Optional: Delete the mirror clone to prevent accidents with it.

I have not actually tried this with GitHub, and you might get warnings or even errors about refs/pull/ references in step 2. If this is a problem, add a "step 1.5":

  • Run git for-each-ref --format="git update-ref -d %(refname)" refs/pull | sh

You may wish to run this without the | sh first, to make sure it generates the correct git update-ref -d commands. This simply deletes all the refs/pull/ names from the mirror clone, so that git push --mirror does not try to push them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文