【问题标题】:Git how to merge master branch of origin repo to master branch of forked repo?Git如何将原始仓库的主分支合并到分叉仓库的主分支?
【发布时间】:2013-11-24 00:26:22
【问题描述】:

我从一个 git repo 分叉并做了一些开发。原始回购也取得了一些进展。我想将它合并到我的仓库中。我不想将任何东西推送到原始仓库。我只想将他们的更改拉到我的并继续在我的存储库上进行开发。

【问题讨论】:

    标签: git github merge


    【解决方案1】:

    好吧,与此同时,我想我猜到了你所说的 fork 是什么意思。根据您在 github 上分叉的问题标签!对吧?

    好的,那么这很容易。 github 上的 fork 基本上是您按下 fork 按钮的存储库的克隆。

    要重新连接到原始存储库,请在本地计算机上执行以下步骤:

    作为示例并尝试一下,我为此分叉了 libgit2...

    $ git clone https://github.com/MyOwnAccount/libgit2.git
    Cloning into 'libgit2'...
    remote: Counting objects: 43058, done.
    remote: Compressing objects: 100% (16412/16412), done.
    remote: Total 43058 (delta 30556), reused 37875 (delta 25761)
    Receiving objects: 100% (43058/43058), 12.22 MiB | 942 KiB/s, done.
    Resolving deltas: 100% (30556/30556), done.
    Checking out files: 100% (2432/2432), done.
    
    $ git remote -v
    origin  https://github.com/MyOwnAccount/libgit2.git (fetch)
    origin  https://github.com/MyOwnAccount/libgit2.git (push)
    
    $ git remote add forkOrigin https://github.com/libgit2/libgit2.git
    
    $ git remote -v
    forkOrigin https://github.com/libgit2/libgit2.git (fetch)
    forkOrigin https://github.com/libgit2/libgit2.git (push)
    origin  https://github.com/MyOwnAccount/libgit2.git (fetch)
    origin  https://github.com/MyOwnAccount/libgit2.git (push)
    
    $ git fetch forkOrigin 
    
    $ git fetch --tags forkOrigin 
    

    现在你已经从你 fork 的 repo 中获得了所有最新的提交、分支和标签。 (您可以直接在远程分支上使用 rebase 或合并 - 此时按您喜欢/需要的方式进行操作,fetch 是现在最简单的显示方式)

    使用这些获取的数据,您可以像往常一样合并、变基、挑选等。

    如果您稍后将更改推送到您自己的存储库,您就完成了。

    【讨论】:

    • 这对你有帮助吗米拉德?然后你就可以接受答案了。否则请询问。祝你的项目好运!
    【解决方案2】:

    如果您按照帖子中的github 建议使用 GitHub,那么您可能将原始存储库分叉到您的 GitHub 帐户,然后从您的分叉中克隆。你可以从原始仓库而不是你的 fork 克隆,但我会假设第一种情况。

    当你从你的 fork 克隆时,git 会自动为它创建一个名为 origin 的远程。要从原始存储库中获取更改,首先您必须为其添加一个遥控器,我们称之为other

    git remote add other the_github_url
    

    接下来,获取这个 repo 的分支:

    git fetch other
    

    您可以稍后使用相同的命令来获取该 repo 中提交的新更改。

    您可以通过以下方式查看另一个遥控器中的分支:

    git branch -r
    

    您可以将另一个远程的 master 合并到您当前的分支中:

    git merge other/master
    

    也就是说,您使用远程名称后跟一个斜杠,然后是分支的名称。

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 2015-02-11
      • 2021-04-09
      • 2019-07-29
      相关资源
      最近更新 更多