简体   繁体   English

Git跟踪上游

[英]Git Tracking Upstream

I am working on a project and I have a central git repo. 我正在做一个项目,我有一个中央git仓库。 This project is a skeleton to be a baseline for a number of forks. 该项目是一个骨架,可作为许多分叉的基线。

Is it possible to configure my local working repository for a fork to track the central for the project as origin and track the skeleton's master as a separate branch named upstream tracking the master of the skeleton to cherry pick changes to the skeleton? 是否可以为fork配置我的本地工作存储库以跟踪项目的中心作为原点并跟踪骨架的master作为一个名为upstream的单独分支跟踪骨架的主人,以挑选对骨架的更改?

I guess I want my workflow to be something like: 我想我希望我的工作流程如下:

Create Skeleton >> Fork Skeleton >> Skeleton Pulls Changes from Fork 2 >> Fork 1 Pulls Changes from Skeleton 创建骨架>>叉骨架>>骨架从叉2拉出变化>>叉1从骨架拉出变化

Is there a better process to do what I have described? 是否有更好的流程来完成我所描述的内容?

Read the " Step 3: Configure remotes " of the GitHub "Fork a Repo" page (I know you didn't mention GitHub, but it is still relevant) 阅读GitHub“Fork a Repo”页面的“ Step 3:Configure remotes ”(我知道你没有提到GitHub,但它仍然相关)

  • origin is the remote address of your fork, that your local clone can pull from/push to origin是fork的远程地址,您的本地克隆可以从/推送到
  • upstream is the remote address of your original repo Skeleton (you can add it with a git remote add upstream https://..../Skeleton.git ) upstream是你的原始repo Skeleton的远程地址(你可以添加git remote add upstream https://..../Skeleton.git

So upstream isn't a branch. 所以上游不是分支。

But you can define a local branch which will have for upstream branch the remote tracking branch master from upstream repo, with git branch : 但是您可以使用git分支定义一个本地分支,该分支将从上游分支上游分支远程跟踪分支主服务器:

git branch --set-upstream upstream_master upstream/master

However, you don't need a local branch, especially if you won't ever make new commits on it: you can compare your master with upstream/master directly, after a git fetch upstream , cherry-picking what you need from upstream/master . 但是,您不需要本地分支,特别是如果您不会对其进行新的提交:您可以直接比较您的主服务器与upstream/master ,在git fetch upstream之后,从upstream/master选择您需要的内容upstream/master

According to your description, you should rebase the forks on the skeleton whenever it changes, using 根据你的描述,你应该在使用时改变骨架上的分叉

$ git rebase upstream

This will transform the situation as follows 这将改变现状如下

initially:
1 - 2 - 3 <- upstream
        \- 4 <- fork

upstream changes:
1 - 2 - 3 - 5 - 6 <- upstream
        \- 4 <- fork

after rebase:
1 - 2 - 3 - 5 - 6 <- upstream
                \- 4 <- fork

In other words, your fork will look like as if it were forked from the most recent version of the skeletton. 换句话说,你的fork看起来好像是从最新版本的骨架分叉。

The disadvantage of this approach is that it changes the history of the forks... If you don't want this, you can just merge upstream into fork (no need to cherry-pick I think). 这种方法的缺点是它改变了fork的历史......如果你不想这样,你可以将上游合并到fork中(我认为不需要挑选)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM