最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Maintaining custom patches on third party code - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Sep 13, 2015 at 0:38 Makoto 107k27 gold badges198 silver badges236 bronze badges asked Jan 18, 2013 at 10:42 MartijnMartijn 3,7644 gold badges40 silver badges66 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

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./tinymce/tinymce.git
$ cd tinymce/
$ git remote add origin [email protected]:tinymce

Then make your patches and push to your repository:

$ git mit -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 bees 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

If you storing TinyMCE in a Git repo, then you could use a Git post-mit-hook to perform the patches after you get a new version of TinyMCE (then mit those patches).

The workflow would be something like:

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

评论列表(0)

  1. 暂无评论