Definition of “downstream” and “upstream”

前端 未结 5 1346
难免孤独
难免孤独 2020-11-21 04:59

I\'ve started playing with Git and have come across the terms \"upstream\" and \"downstream\". I\'ve seen these before but never understood them fully. What do these terms

5条回答
  •  春和景丽
    2020-11-21 05:18

    When you read in git tag man page:

    One important aspect of git is it is distributed, and being distributed largely means there is no inherent "upstream" or "downstream" in the system.

    , that simply means there is no absolute upstream repo or downstream repo.
    Those notions are always relative between two repos and depends on the way data flows:

    If "yourRepo" has declared "otherRepo" as a remote one, then:

    • you are pulling from upstream "otherRepo" ("otherRepo" is "upstream from you", and you are "downstream for otherRepo").
    • you are pushing to upstream ("otherRepo" is still "upstream", where the information now goes back to).

    Note the "from" and "for": you are not just "downstream", you are "downstream from/for", hence the relative aspect.


    The DVCS (Distributed Version Control System) twist is: you have no idea what downstream actually is, beside your own repo relative to the remote repos you have declared.

    • you know what upstream is (the repos you are pulling from or pushing to)
    • you don't know what downstream is made of (the other repos pulling from or pushing to your repo).

    Basically:

    In term of "flow of data", your repo is at the bottom ("downstream") of a flow coming from upstream repos ("pull from") and going back to (the same or other) upstream repos ("push to").


    You can see an illustration in the git-rebase man page with the paragraph "RECOVERING FROM UPSTREAM REBASE":

    It means you are pulling from an "upstream" repo where a rebase took place, and you (the "downstream" repo) is stuck with the consequence (lots of duplicate commits, because the branch rebased upstream recreated the commits of the same branch you have locally).

    That is bad because for one "upstream" repo, there can be many downstream repos (i.e. repos pulling from the upstream one, with the rebased branch), all of them having potentially to deal with the duplicate commits.

    Again, with the "flow of data" analogy, in a DVCS, one bad command "upstream" can have a "ripple effect" downstream.


    Note: this is not limited to data.
    It also applies to parameters, as git commands (like the "porcelain" ones) often call internally other git commands (the "plumbing" ones). See rev-parse man page:

    Many git porcelainish commands take mixture of flags (i.e. parameters that begin with a dash '-') and parameters meant for the underlying git rev-list command they use internally and flags and parameters for the other commands they use downstream of git rev-list. This command is used to distinguish between them.

提交回复
热议问题