【问题标题】:Import/export with stgit and git patches使用 stgit 和 git 补丁导入/导出
【发布时间】:2011-05-29 00:38:29
【问题描述】:

我有 git repository A 和 git repository B,我想使用 stgit 将 repo A 中的一些补丁应用到 repo B。

到目前为止,我的理解是我采取了这些步骤:

$ stg clone smthA.git repoA
$ cd repoA
$ stgit uncommit --number=100
$ stgit export
$ cd ../../repoBdir
$ stgit import ../../repoA/patchdir/patch_name_1

谁能确认我这是正确的程序?我错过了什么吗? 在某些情况下,如何解决 "Trying to uncommit .... which does not have exactly one parent" 出现的 "$ stgit uncommit" 错误?

从做过这件事的人那里学到了什么建议或教训?

【问题讨论】:

    标签: git patch


    【解决方案1】:

    您列出的步骤基本上是正确的。如果您需要将输出定向到共享驱动器,--dir 选项会很有用。如果您想导入整个补丁集,--series (-s) 选项会很有帮助。我在工作中经常使用它来在新机器上初始化一个 stg git 工作副本:

    # On Machine A (existing StGit repo with all patches applied)
    $ stg export --dir /y/projects/ttc_dev_stg_patches/master
    Checking for changes in the working directory ... done
    
    # On Machine B ('pristine' StGit repo with no patches)
    $ stg series [<-- should have no output!]
    $ stg import -s /y/projects/ttc_dev_stg_patches/master/series
    Checking for changes in the working directory ... done
    Importing patch "remove-stl-at" ...
      Invoking the editor: "vim .stgitmsg.txt" ... done
    done
    Importing patch "wldap32-fix" ...
      Invoking the editor: "vim .stgitmsg.txt" ... done
    done
    Importing patch "cmake-fixes" ...
      Invoking the editor: "vim .stgitmsg.txt" ... done
    done
    Now at patch "cmake-fixes"
    

    如果您不想导入每个补丁,您可以像在示例中那样单独指定它们。

    另一个常见的需求是同步多个工作副本中的补丁(可能在不同的机器上)。 stg sync 是在这种情况下使用的命令:

    # On Machine B (existing StGit repo)
    $ stg series
    + remove-stl-at
    + wldap32-fix
    > cmake-fixes
    $ stg sync --all -s /y/projects/ttc_dev_stg_patches/master/series
    Checking for changes in the working directory ... done
    Popping patches "cmake-fixes" - "wldap32-fix" ... done
    Synchronising "remove-stl-at" ... done (updated)
    Fast-forwarded patch "wldap32-fix"
    Synchronising "wldap32-fix" ... done
    Fast-forwarded patch "cmake-fixes"
    Synchronising "cmake-fixes" ... done (updated)
    

    关于尝试取消提交具有多个父项的修订的错误:您基本上不能这样做。来自stg-uncommit(1) 手册页:

    只有只有一个父级的提交才能被取消提交;其他 也就是说,你不能取消提交合并。

    这是有道理的。如果历史不是线性的,StGit 就无法知道它应该使用哪个父提交。根据您的需要,一种可能的解决方法可能是从其中一个父级创建一个临时分支,然后从另一个父级中挑选您需要的提交。这将创建一个线性历史记录,然后您可以在其上运行stg uncommit 以创建一个补丁系列。如果您只是想生成一个完全适用于某些特定源树快照的补丁集,这可能没问题。但是,如果您正在做比这更复杂的事情,您很可能会在使用这种方法时遇到麻烦。 (这是一个难题;请参阅this question 了解更多信息。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 2015-05-21
      • 1970-01-01
      • 2011-06-13
      • 2018-05-20
      相关资源
      最近更新 更多