在第三方代码上维护自定义补丁 [英] Maintaining custom patches on third party code

查看:44
本文介绍了在第三方代码上维护自定义补丁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm building a web application that uses a third party JavaScript library (TinyMCE).

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

My application has some specific needs which require me to patch the library in a few places. The patches are easy (less than a dozen lines), but since they are specific to our use case and not bugs.

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

I'd like to be able to update when new versions of the library itself are released, which would overwrite our changes in our Git repository.

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

I need a way to ensure our patches are always applied before pushing the updated library to a production server. Since the changes are very small, it wouldn't be an issue to apply them manually.

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

How can I ensure my patches to third party code are applied in our repository when updating the third party code?

推荐答案

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

Create a repository for tracking the third-party code, and put your patches in a separate branch. When you need the latest release fetch the changes and rebase your branch.

例如:

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

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

Then make your patches and push to your repository:

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

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

At this point your repository looks like this:

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

其中 X 是您的补丁.

Where X is your patch.

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

Now set a branch to fetch new revisions from the github remote:

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

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

So your repository becomes like this (git branch is smart enough to use as the origin the last revision in the github remote):

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

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

At last rebase your master branch on tinymce_import:

$ git checkout master
$ git rebase tinymce_import

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

这篇关于在第三方代码上维护自定义补丁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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