git:如何重新叉一个syc? [英] git: how to re-syc a fork?

查看:84
本文介绍了git:如何重新叉一个syc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要遵循的工作流程是:

the workflow we are required to follow is this:

  1. 将github上的项目分叉到您自己的私人githib帐户中.
  2. 将分支的项目克隆到本地计算机上.
  3. 在本地计算机上创建(主节点的)功能分支.
  4. 将分支提交到分叉的仓库中.
  5. 在主存储库上执行拉取请求,将其派生到派生存储库上的新分支.

这很棒,但是几天后,我们需要创建一个新的功能分支.同时,一些功能已提交给主仓库中的主服务器.

This is great, but a few days later we need to create a new feature branch. In the mean time some features have been commited to master on the main repo.

如果我们现在在存储库上创建一个新分支,将其推送到我们的分叉副本中,那么我们将使用旧的过时代码.

If we now create a new branch on our repo, push it to our forked copy, we are working with old out of date code.

那么我们如何将最新的母版从我们没有权限的原始存储库中提取到派生的存储库中,然后再到本地存储库中?

So how do we pull the latest master from the original repo we dont have permission on, into our forked repo, then down to our local repo?

或者最好总是为每个功能分支创建一个新的fork,并尝试快速工作(因为代码很快就会过时,因为我们无法提取其他人推送的更改).

Or is it best to always create a new fork for each feature branch, and try to work quickly (as the code will soon be out of date as we cant pull in changes pushed by others).

这是关于该主题的一些讨论:

This has some discussion on the subject:

在github上进行分叉上游跟踪的最佳实践

但是缺少我需要的东西,那就是如何使用实际的git命令来做到这一点.

But is missing what I need, which is how to do this with actual git commands.

例如我们现在拥有的是这样:

E.g. what we have now is this:

  1. 使用github web ui在github上将其分叉到本地仓库
  2. git clone https://github.com/myname/aproject
  3. git remote add origin https://github.com/myname/aproject #不知道为什么我们必须这样做.
  4. git checkout -b mybranch
  5. 做些工作.
  6. git commit -m ...
  7. git push origin mybranch#将新分支放在我们的个人github分叉副本上
  8. 通过github ui发出拉取请求.
  1. fork on github to local repo using github web ui
  2. git clone https://github.com/myname/aproject
  3. git remote add origin https://github.com/myname/aproject # not sure why we have to do this.
  4. git checkout -b mybranch
  5. do some work.
  6. git commit -m ...
  7. git push origin mybranch # puts the new branch on our personal github forked copy
  8. make a pull request via github ui.

我们不知道什么是我们需要什么命令来从原始github存储库中获取最新的主更新,一直到我们在私有github帐户中该存储库的分叉副本,然后最后到我们的本地克隆副本.分叉的仓库.

What we dont know is what commands we would need to get the latest master updates from the original github repo, through to our forked copy of that repo on in our private github account, then finally down to our local cloned copy of the forked repo.

例如我们如何告诉github烤的分叉仓库从分叉的仓库进行更新?

E.g. how would we tell the github hoasted forked repo to update itself from the repo it was forked from?

或者,如果不可能的话,可以将最新的母版直接从原始github托管存储库中提取到开发人员PC上的本地克隆副本中(绕过devs.私有github帐户中的分叉存储库)

Or, if this is not possible, a way to pull the latest master from the original github hosted repo directly to the local cloned copy on the developers PC (bypassing the forked repo in the devs. private github account)

我也看到了这篇文章:

如何更新GitHub分叉的存储库?

可接受的答案是这样:

git remote add upstream https://github.com/whoever/whatever.git
git fetch upstream
git checkout master
git rebase upstream/master

  1. fork如何获取新的主更新?这样只会更新您本地存储库的主文件吗?
  2. 这意味着您本地克隆的回购有2个父母-原始回购和分叉的回购.这怎么工作?您如何从两个不同的仓库中获取一个仓库?大概,分叉的存储库将永远不知道从原始存储库提取的更新吗?接下来,当您将第二个功能分支推回到您的分叉存储库时,它将基于错误的代码,因此,分叉存储库将与您的本地存储库不同,并且如果您重新签出所有内容,则无法在本地进行测试从您的分叉存储库到新目录?

推荐答案

如另一个答案所述,拥有2个遥控器没有什么不对.实际上,要提交功能分支,您不必执行任何重新同步或派生.您需要遵循所谓的.

As the other answer describes, there is nothing wrong in having 2 remotes. Actually, to submit feature branches, you do not have to perform any re-syncing or your fork. You need to follow so-called triangular workflow (search there for "Improved support for triangular workflows").

tl:dr:

<fork in Web>
git clone <URL>
cd clone
git add upstream <upstream URL>
<later>
git fetch upstream
git checkout -b <feature> upstream/master
<develop, commit>
git push origin <feature>
<make PR in Web>

如您所见,您只在这里更新了fork的<feature>分支,该分支是上游最新的-只是您需要提交PR的分支.基本上,派生存在的全部目的是拥有一个分支,然后没有理由在派生中维护其他分支.

As you can see, you only update here the <feature> branch of your fork, which is up-to-date with upstream - just the one you need to submit a PR. Basically, the whole purpose for the fork to exist is to have that one branch, then there is no reason to maintain other branches in the fork.

问题在github上用fork跟踪上游的最佳实践不仅如此,它还需要跟踪分叉特有的更改".当达到这样的目标时,就有一项任务是保持这些更改为最新状态,而不是之前.

The question Best practice for tracking upstream in fork on github goes beyond that, it needs to "tracking of changes unique to the fork". When such goal arises then there is a task of maintaining those changes up-to-date, but not before.

这篇关于git:如何重新叉一个syc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆