本地分支机构在GitHub的“网络”上显示视图 [英] Local branches show-up on GitHub's "Network" view

查看:138
本文介绍了本地分支机构在GitHub的“网络”上显示视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用Git,我们的工作流由一个'dev'和'master'分支组成,它位于GitHub和每个开发人员的本地存储库上。没有工作是直接在'master'或'dev'上执行的,而是在本地分支上进行的,只有合并发生在'dev'上,然后在'master'上进行。我们不推送本地分支到GitHub。

由于某些原因,开发人员的本地分支出现在GitHub的网络视图中,这使得网络图(I应该指出分支本身并不存在于GitHub的分支列表下)。



我的问题是这是否是正常行为并且是自动发生的显示'开发者'和'主'的变化来自何处,或者是因为某人错误地推动了本地分支并在以后删除它?如果是后者,有没有办法清理混乱?

解决方案

您在网络中看到的工件视图可能是基于合并的工作流程的痕迹。



当合并操作导致合并提交时 * (即它不是快进),存储库历史记录的 DAG 模型将包含代表两个分支的部分。当非本地分支被推送时,它的祖先将包括最初在本地分支上提交的提交。

* 通过使用 git merge --no-ff 或者因为两个分支已经超出了它们的合并基础。


考虑一个假设的系列事件和结果历史记录DAG +在中央存储库中引用:

  A $ git fetch&& git checkout -b foo central / dev 
#A工作并提交给她的本地分支
B $ git fetch&& git checkout -b bar central / dev
#A和B工作并提交到它们的本地分支
A $ git checkout dev&& git pull&&
git merge --no-ff foo&& git push central dev
#B工作并提交给他的本地分支
C $ git fetch&& git checkout -b quux central / dev
#B和C工作并提交到他们的本地分支
B $ git checkout dev&& git pull&&
git merge --no-ff bar&& git push central dev
C $ git checkout dev&& git pull&&
git merge --no-ff quux&& git push central dev
D $ git fetch&&
git checkout master&& git pull&&
git merge --no-ff dev&& git push central master

--- o --- o ------------------------------ -D master
\ /
\ o --- o --- o /(在C的本地仓库中是quux)
\ o --- o / \ /(在A的本地存储库中是foo)
\ / \ / \ /
o ------- A --------- B --- C dev
\ /
o --- o ---- o ---- o(在B的本地存储库中存储)

直接将本地( foo bar quux )分支直接推送到中央储存库。然而,他们的提交被合并提交所引用,这些合并提交被推送到中央存储库中的分支(以及后来分配给 master 分支)。



我怀疑GitHub网络视图会显示这些间接推送的分支。



如果要消除这种拓扑证据分支机构,您将需要转移到基于rebase操作而不是合并操作的工作流程(这意味着本地分支的原始分支点将被丢弃,这对您的整个工作流程可能并非重要)。



不要陷入让DAG看起来漂亮的困境。工具不在乎DAG是否丑陋,你也不应该。您应该专注于挑选并正确使用生成DAG的分支工作流程,以便工具为您提供有用的工作。


We are using Git and our workflow consists of a 'dev' and 'master' branch which lives on GitHub and each developer's local repository. No work is performed directly on 'master' or 'dev', but rather in local branches and only merges happen on 'dev' and later with 'master'. We do not push local branches to GitHub.

For some reason developers' local branches show up in the "Network" view on GitHub and this clutters up the network diagram (I should point out that the branch itself doesn't exist under the list of branches on GitHub).

My question is whether this is normal behavior and happens automatically as a means of showing where the changes to 'dev' and 'master' come from or is it because someone pushed a local branch by mistake and deleted it later? If it's the latter, is there a way to clean-up the clutter?

解决方案

The artifacts you are seeing in the "network" view are probably traces of your merge-based workflow.

When a merge operation results in a merge commit* (i.e. it is not a "fast-forward"), the DAG model of the repository's history will include portions that represent both branches. When the non-local branch is pushed, its ancestry will include the commits that were made originally on the local branch.
*Either by using git merge --no-ff or because both branches had moved beyond their merge base.

Consider a hypothetical series of events and the resulting history DAG+refs in the central repository:

A$ git fetch && git checkout -b foo central/dev
# A works and commits to her local branch
B$ git fetch && git checkout -b bar central/dev
# A and B work and commit to their local branches
A$ git checkout dev && git pull &&
   git merge --no-ff foo && git push central dev
# B works and commits to his local branch
C$ git fetch && git checkout -b quux central/dev
# B and C work and commit to their local branches
B$ git checkout dev && git pull &&
   git merge --no-ff bar && git push central dev
C$ git checkout dev && git pull &&
   git merge --no-ff quux && git push central dev
D$ git fetch && 
   git checkout master && git pull &&
   git merge --no-ff dev && git push central master

---o---o-------------------------------D  master
        \                             /
         \             o---o---o     /      (was quux in C's local repository)
          \   o---o   /         \   /       (was foo in A's local repository)
           \ /     \ /           \ /
            o-------A---------B---C       dev
             \               /
              o---o----o----o               (was bar in B's local repository)

At no point were the local (foo, bar, quux) branches ever directly pushed to the central repository. However, "their" commits are referenced by the merge commits that are pushed to the dev branch (and later to the master branch) in the central repository.

I suspect that the GitHub network view is showing you these indirectly pushed branches.

If you want to eliminate such topological evidence of branches, you will need to move to workflow that is based on rebase operations instead of merge operations (this implies that the original "fork point" of the local branch will be discarded, which may or may not be important to your overall workflow).

Do not get bogged down trying to make the DAGs look "pretty". The tools do not care if the DAGs are "ugly", neither should you. You should concentrate on picking and properly using a branching workflow that produces a DAG that lets the tools do useful work for you.

这篇关于本地分支机构在GitHub的“网络”上显示视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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