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

编程入门 行业动态 更新时间:2024-10-22 04:27:11
在第三方代码上维护自定义补丁(Maintaining custom patches on third party code)

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

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

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

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

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

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.

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?

最满意答案

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

例如:

$ 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 remote中最后一个版本的原点):

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

最后在tinymce_import上修改你的分支:

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

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.

For example:

$ 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

Where X is your patch.

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

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

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

更多推荐

本文发布于:2023-08-02 04:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1368380.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   第三方   补丁   代码   Maintaining

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!