【问题标题】:Maintaining custom patches on third party code维护第三方代码的自定义补丁
【发布时间】:2013-01-02 01:27:47
【问题描述】:

我正在构建一个使用第三方 JavaScript 库 (TinyMCE) 的 Web 应用程序。

我的应用程序有一些特定的需求,需要我在几个地方修补库。补丁很简单(不到十几行),但因为它们是特定于我们的用例而不是错误。

我希望能够在库本身的新版本发布时进行更新,这将覆盖我们在 Git 存储库中的更改。

我需要一种方法来确保在将更新的库推送到生产服务器之前始终应用我们的补丁。由于更改非常小,因此手动应用它们不会有问题。

在更新第三方代码时,如何确保在我们的存储库中应用我的第三方代码补丁?

【问题讨论】:

    标签: javascript version-control patch


    【解决方案1】:

    创建一个用于跟踪第三方代码的存储库,并将您的补丁放在一个单独的分支中。当您需要最新版本时,请获取更改并rebase您的分支。

    例如:

    $ git clone --origin github https://github.com/tinymce/tinymce.git
    $ cd tinymce/
    $ git remote add origin git@myrepo.example.org:tinymce
    

    然后制作补丁并推送到您的存储库:

    $ git commit -m "my patches to tinymce"
    $ git push --set-upstream origin master
    

    此时您的存储库如下所示:

    (0) --- (1) --- ... (n) --- (X)
                                 |
                               master
    

    X 是你的补丁。

    现在设置一个分支以从 github 远程获取新修订:

    $ git branch tinymce_import github/master
    $ git checkout tinymce_import
    $ git pull --ff-only
    

    所以你的存储库变成了这样(git branch 足够聪明,可以将 github 远程中的最后一个修订版用作原点):

                               master
                                 |
                         +----- (X)
                         |
    (0) --- (1) --- ... (n) --- (n+1) --- ... (n+m)
                                                |
                                          tinymce_import
    

    最后在 tinymce_import 上重新设置你的 master 分支:

    $ git checkout master
    $ git rebase tinymce_import
    
                                                      master
                                                        |
                                                +----- (X)
                                                |
    (0) --- (1) --- ... (n) --- (n+1) --- ... (n+m)
                                                |
                                          tinymce_import
    

    【讨论】:

      【解决方案2】:

      如果您将 TinyMCE 存储在 Git 存储库中,那么您可以在获得新版本的 TinyMCE 后使用 Git post-commit-hook 执行补丁(然后提交这些补丁)。

      工作流程类似于:

      [get new version of TinyMCE]
      ["git commit -a" to update all tracked files]
      [post-commit-hook patches TinyMCE]
      ["git commit -a" to pick up all of the changes from the patches]
      

      【讨论】:

        猜你喜欢
        • 2013-07-20
        • 1970-01-01
        • 2014-04-30
        • 2012-01-06
        • 2019-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多