【问题标题】:What's the difference between `arc graft` and `arc patch`?“弧形移植”和“弧形贴片”有什么区别?
【发布时间】:2019-01-17 02:01:34
【问题描述】:

arc help --full | lessgraft 揭示了这一点:

  graft revision

      Grafts revision and its dependencies (if any) onto your working tree.

      --force
          Do not run any sanity checks.

      --skip-landed
          Do not try to patch landed/closed diffs.

这是patch

  patch D12345
  patch --revision revision_id
  patch --diff diff_id
  patch --patch file
  patch --arcbundle bundlefile
      Supports: git, svn, hg
      Apply the changes in a Differential revision, patchfile, or arc
      bundle to the working copy.

      --arcbundle bundlefile
          Apply changes from an arc bundle generated with 'arc export'.

这对我来说很模糊。用“graft”这个词来描述“graft”的含义对我没有多大帮助。


对于那些不知道的人,arc (Arcanist) 是“Phabricator”内部的一个命令行工具,它的作用类似于 Git(甚至是 Mercurial 和 Subversion)的高级包装器,以帮助开发大型软件项目的流程。这里有几个链接:

https://phacility.com/phabricator/

Phabricator 最初是作为 Facebook 的内部工具开发的。[7][8][9] Phabricator 的主要开发人员是 Evan Priestley。[1] Priestley 离开 Facebook,在一家名为 Phacility 的新公司继续 Phabricator 的开发。 [2] https://en.wikipedia.org/wiki/Phabricator

【问题讨论】:

    标签: git phabricator arcanist


    【解决方案1】:

    2020 年 3 月 19 日更新:

    请注意arc flowarc cascade 显然不是mainstream version of Phacility's arcanist 的一部分。相反,它们只是Uber fork of arcanist 的一部分。例如,arc flow 的一些源代码可以在 here 找到。此外,arc cascade 也只是 Uber 的 fork arcanist 功能,它的一些 arc cascade 源代码可在 here 找到。
    了解如何安装 Uber 的 fork of arcanist 以开始使用这些功能常规git 工作流程中的功能(如果不需要,您无需使用奥术师的任何其他功能),请跳至此答案的底部


    2019 年 1 月的原始答案:

    所以,经过一些试验和反复试验,我想我想通了:

    arc graftarc patch 在后台都使用git cherry-pick,并完成类似的事情。但是,它们有一些细微的差别,有时arc patch 会失败,您必须使用带有--skip-landed 标志的arc graft(更新:或者也许带有--skip-dependencies 标志的arc patch 也可以使用?)。

    例子:

    # cherry-pick their "D999" "diff" (branch) onto your current branch, while creating 
    # a new single branch for you named "arcpatch-D999", skipping dependencies in case 
    # they've already landed on the branch (ex: master) you currently have checked out.
    arc patch --skip-dependencies D999 
    

    # cherry-pick their "D999" "diff" (branch), *as well as all parent branch(es) it 
    # depends on*, onto your current branch, while creating the entire dependency tree 
    # of branches for you, exactly as the submitter originally had on their local 
    # machine, skipping any commits that have already landed on your local branch 
    # (ex: master) you currently have checked out
    arc graft --skip-landed D999 
    

    想象你的arc flow 依赖树只包含“master”分支:

    master
    

    然而,一位同事有以下 arc flow 依赖树:

    master                              
    └──new_feature_1
       └──new_feature_2 
    

    顺便说一句:arc flow 依赖树是什么? Ans:它是一个树形结构,通过arc flow 命令显示,它显示了哪些分支依赖于什么。作为人类,您手动跟踪是一件有点武断的事情,因为您知道一个功能依赖于另一个功能。要建立“依赖关系”,您有两种选择:

    1. 调用arc flow new_branch_name 创建一个新的子分支,而您当前已签出您想要成为父分支的分支,或者:
    2. 使用 git 创建一个新分支,然后将其上游设置为您想要的父级。例如:

      git branch new_branch_name
      git checkout new_branch_name # Or use `git checkout -b new_branch_name` to do both at once
      git branch --set-upstream-to=upstream_branch_name # or `git branch -u upstream_branch_name` for short
      

    现在,arc flow 将显示您的依赖关系树。这使您可以将 arc cascade 之类的事情从父级传递到其子级,这只是在执行从父级到子级的自动递归 git rebases(即:将子级重新定位到父级)。

    结束。


    无论如何,通过上面显示的依赖关系树,您的同事已签出“new_feature_2”,他们arc diff 供您查看。您转到基于 Web 的“差异化”工具并开始查看更改。但是,您想对其进行测试。这意味着您需要将他们的差异拉到您的本地机器上。您有两个选择:1. arc patch 他们的差异(依赖树感知分支)到您的本地 master,或 2. arc graft 他们的差异到您的本地 master。

    假设它们的差异是“D999”,并且您当前已签出“主”分支,您的命令和生成的依赖树将如下所示:

    1. arc patch D999。你现在有了这棵树,你新创建的“arcpatch-D999”是他们的“new_feature_2”分支:

      master
      └──arcpatch-D999 
      
    2. arc graft D999。您现在拥有这棵树,就像他们拥有的一样:

      master                              
      └──new_feature_1
         └──new_feature_2 
      

    但是,(我认为,基于我的问题)有时当他们有这样的多代依赖树时,arc patch 会失败(给出一个错误,显示“Cherry Pick Failed!”),并且在这样的情况下一个你必须使用arc graft的案例!但是,如果他们的主人与您的主人不完全相同(几乎可以肯定不会,因为他们可能会在一段时间前拉动他们的主人,而您应该刚刚拉动您的主人以确保您拥有最新的),那么您尝试移植物或补丁将失败。失败很可能与分支历史记录中的某些提交包含已经登陆并存在于您的 master 中的更改有关。 解决方案是使用arc graft D999 --skip-landed,这将允许您获取他们的差异并将其拉下,镜像他们的arc flow 依赖树。 在这种情况下,arc patch D999 可能会继续失败直到他们拉出最新的 master 和 arc cascade(或 git rebase 两次),然后 re-arc diff 将他们的更改推送到服务器,此时您可以将 arc patch D999 成功发送到您的 master 上。但是,因为您不能总是让他们立即变基/arc cascade,所以现在就执行arc graft D999 --skip-landed 并完成!让他们变基并在他们到达时重新arc diff

    然而,一个小问题是,如果你经常arc grafting,可能会混淆谁创建了哪些分支(你还是其他人?),所以我建议你养成嫁接新分支的习惯分支你自己命名,如下,只是为了组织:

    git checkout master # same as `arc flow master`
    git pull origin master # pull latest master
    arc flow graft-D999 # create and checkout a new child branch you are calling "graft-D999" (name it appropriately)
    arc graft D999 --skip-landed # graft their entire dependency tree onto your branch "graft-D999"
    

    您的依赖关系树现在如下所示:

    master                              
    └──graft-D999
       └──new_feature_1
          └──new_feature_2 
    

    太棒了!尼斯和有组织的。现在您可以查看“new_feature_2”并对其进行编译和测试。但是请注意,“master”和“graft-D999”将是完全相同的分支,但没关系。

    如何安装优步的奥术分叉

    (如果您想在自己的 git 工作流程中开始使用 arc flowarc cascade):

    注意:Arcanist 在 Windows(在 git for Windows git bash 终端内)、Mac 和 Linux 上运行。我将只介绍 Linux 安装说明。要获得在其他系统中安装的帮助,请参阅下面的参考资料。

    Linux Ubuntu 安装:

    cd 到您希望安装文件所在的位置,然后执行以下操作:

    # 1. Obtain the Uber fork of the arcanist program by cloning it into an "uber" directory.
    mkdir uber
    git clone https://github.com/uber/arcanist.git uber
    # 2. Symbolically link the `arc` program to your ~/bin directory so you can call `arc` from anywhere.
    # - this assumes that ~/bin is in your PATH.
    # Ensure the ~/bin dir exists; if just creating this dir for the first time you may need to log out of Ubuntu
    # and log back in AFTER running the `mkdir` command below, in order to force your ~/.profile script to 
    # automatically add ~/bin to your PATH (assuming your ~/.profile script does this, as default Ubuntu scripts do).
    mkdir -p ~/bin
    ln -s $PWD/uber/arcanist/bin/arc ~/bin
    

    现在尝试运行arc。它应该会失败并显示以下消息:

    $ arc
    ERROR: Unable to load libphutil. Put libphutil/ next to arcanist/, or update your PHP 'include_path' to include the parent directory of libphutil/, or symlink libphutil/ into arcanist/externals/includes/.
    

    所以,请执行以下操作:

    # 3. Obtain the libphutil program.
    # - Note that git cloning it like this `git clone https://github.com/phacility/libphutil.git` will NOT work anymore
    # for Uber's fork of arcanist because the libphutil project is now empty. So, do this instead:
    sudo apt install libphutil
    # 4. symbolically link the libphutil program into arcanist.
    # First, we need to know where it is installed.
    dpkg -L libphutil
    # Now look at the output from the above command. Mine shows libphutil is installed in "/usr/share/libphutil/",
    # so do the following:
    ln -s /usr/share/libphutil uber/arcanist/externals/includes
    

    现在测试arc 命令,您应该会看到以下内容:

    $ arc
    Usage Exception: No command provided. Try `arc help`.
    

    运行arc help 可查看帮助菜单,或运行arc help --full 可查看完整的帮助菜单。

    让我们用 grep 查找 flowcascade 以证明它们仅在 Uber 分支的帮助菜单中(但不是主要奥术师):

    在完整的帮助菜单中搜索flow

    $ arc help --full | grep flow
              This workflow is primarily useful for writing scripts which integrate
                  soft version of '' used by other workflows.
          flow [options]
          flow name [options]
          flow name upstream [options]
              step in the standard Differential pre-publish code review workflow.
              The workflow selects a target branch to land onto and a remote where
              Consulting mystical sources of power, the workflow makes a guess
              step in the standard Differential pre-publish code review workflow.
              The workflow selects a target branch to land onto and a remote where
              Consulting mystical sources of power, the workflow makes a guess
              code review workflow.
              The workflow selects a target branch to land onto and a remote where
    

    还有完整帮助菜单中的cascade

    $ arc help --full | grep -A 4 cascade
          cascade [--halt-on-conflict] [rootbranch]
    
              Automates the process of rebasing and patching local working branches
              and their associated differential diffs. Cascades from current branch
              if branch is not specified.
    --
                  Rather than aborting any rebase attempts, cascade will drop the
                  user
                  into the conflicted branch in a rebase state.
    

    参考资料:

    1. Pacility 的奥术师(缺少 arc flowarc cascade 功能):https://github.com/phacility/arcanist
    2. Uber 的 Arcanist 分支(已添加 arc flowarc cascade 功能):https://github.com/uber/arcanist
    3. Arcanist 用户指南:https://secure.phabricator.com/book/phabricator/article/arcanist/ --> 有关如何在 Windows、Mac、Linux 或 FreeBSD 中安装 Arcanist 的说明,请参阅“安装 Arcanist”部分。
    4. ERROR: Unable to load libphutil

    相关:

    1. Output of git branch in tree like fashion

    【讨论】:

    • 好的。 +1。所以 arc 的嫁接性质似乎与我在自己的回答中提到的 Git 中的那个无关。
    • 是的,我仍在努力思考这一切,但我认为不会。
    【解决方案2】:

    这可能与git grafts 相关,您可以在其中进行提交/修订,并更改其父提交,从而更改存储库的历史记录。
    (虽然,since Git 2.18, Q2 2018, graft has been superseded by git ref/replace/

    与补丁不同,补丁只是从现有差异创建新的提交/修订,添加到存储库的历史记录。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多