我正在构建一个使用第三方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_importCreate 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:tinymceThen make your patches and push to your repository:
$ git commit -m "my patches to tinymce" $ git push --set-upstream origin masterAt this point your repository looks like this:
(0) --- (1) --- ... (n) --- (X) | masterWhere 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-onlySo 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_importAt 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更多推荐
发布评论