【问题标题】:Git pull from someone else's forkGit 从别人的 fork 中拉取
【发布时间】:2017-06-28 15:49:20
【问题描述】:

我们是两个学生,他们在我们的在线存储库(不同的存储库)上工作,该存储库是从一个共同的上游存储库分叉出来的。

假设其他学生在特定分支上进行了更改、提交和推送到他的仓库。

  1. 如何将这些更改提取到我自己的本地存储库中?

  2. 我是否需要提交这些更改并将其推送到我的暂存区域?

谢谢!

【问题讨论】:

    标签: git git-commit git-push git-pull git-fork


    【解决方案1】:

    只需在您的 own 存储库中添加一个新的遥控器(例如,other)。然后将 other/<branch> 更改拉入您的本地分支(例如,add-other-changes)。推送到您自己的分叉仓库 (origin/add-other-changes)。现在,当您完成 add-other-changes 分支后,创建一个拉取请求并与 origin/master 合并。

    • 将其他 repo 的更改拉入您自己的 repo:

        # go into your own repo
        $ git remote add other <other-student-repo-url>  # add a new remote with other's repo URL
      
        $ git fetch other         # sync/update local with other's repo
      
        $ git checkout -b add-other-changes       # create a new branch named 'add-other-changes'                    
        $ git pull other <specific-branch-name>   # pull other/<branch> changes           
      
        $ git push origin HEAD    # push changes to your own(origin) forked repo `add-other-changes` branch
      

    【讨论】:

    • 完美!谢谢你:)
    • 现在已经完成了,如何跟踪其他学生的变化?
    • git fetch other 将使用其他学生的 repo 更改更新您的本地。如果您需要任何特定的分支更改,只需将其拉到git pull other &lt;specific-branch&gt;
    【解决方案2】:

    如果你们都想在同一个项目上工作,那么你们不应该两次分叉存储库。您或您的朋友(不是两者)应该分叉存储库,然后你们俩都应该在本地克隆分叉的一个(需要由分叉存储库的人授予权限)。

    完成此操作后,当项目成员想知道远程是否有新更改时,他们可以使用git remote update 或更常见的git fetch origin

    如果你在同一个分支上工作,并且你想用远程分支更新你的本地分支git pull origin &lt;branh_name&gt;

    如果有人做出了应该共享的更改:

    git add file_path_1 file_path_2 directory_path1 ...
    git commit -m "<your brief message>"
    git push origin <branch_name>
    

    【讨论】:

      【解决方案3】:

      提交并推送您的工作分支。然后从主分支合并到您的分支。确保所有构建和解决任何冲突。提交并推送您的分支。现在将您的分支合并到主分支中,它应该可以工作了。

      【讨论】:

        猜你喜欢
        • 2011-08-02
        • 2016-08-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-04
        • 1970-01-01
        • 1970-01-01
        • 2017-05-26
        相关资源
        最近更新 更多