git 工作流程使自定义修改的开源软件保持最新状态?

发布于 2024-09-25 09:49:53 字数 403 浏览 2 评论 0原文

我们大学在我们管理的服务器上向校园各部门提供网络托管。安装开源第三方程序需要修改文件权限和程序中的代码才能运行。 (如果您熟悉的话,我们正在使用 suEXEC。)

我们目前通过安装程序脚本提供 WordPress。用户上传最新的稳定版本,并通过 SSH 运行服务器端 PHP 脚本。此 PHP 脚本修改所有文件/文件夹的文件权限,添加/删除各个文件中的一些代码,并创建一些新文件。当发布新的稳定版本时,此安装程序脚本是一个繁琐的平衡行为。

我想开始使用版本控制(特别是 git)来跟踪我们的自定义更改,而不是依赖脚本来进行更改,但我不确定要使用的工作流程。我熟悉分支和合并,但不确定在发布新版本时如何集成旧的更改。

我的 git 工作流程应该如何集成 WordPress 核心的新更改,同时保留旧的自定义更改?

Our University provides web hosting to campus departments on servers we manage. Installing open-source third-party programs requires modifying file permissions and code in the program before it will run. (We're using suEXEC, if you're familiar.)

We currently offer WordPress via an installer script. The user uploads the newest stable release, and runs a server-side PHP script via SSH. This PHP script modifies file permissions of all files/folders, adds/removes some code in various files, and creates a few new files. This installer script is a cumbersome balancing act when a new stable version is released.

I want to start using version control (specifically git) to track our custom changes instead of relying on a script to make the changes, but am unsure of the workflow to use. I'm familiar with branching and merging, but not sure how to integrate our old changes when a new release is issued.

What should my git workflow be to integrate the new changes from the WordPress core, but also preserve our older custom changes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-10-02 09:49:53

我建议将您的更改保留在一个分支中,并在每次更新时根据 WordPress 的最新版本重新调整该分支。在粗略的时间表中...

              +-- WordPress 1.0
              v
[master] --*--*
               \
[custom]        *--*--*     <- your customizations

当您想要更新 WordPress 时,切换到 master 并使用最新的源进行新的提交(或使用 git-svn 使 master 保持同步):

              +-- WordPress 1.0
              |     +-- WordPress 1.1
              v     v
[master] --*--*--*--* 
               \
[custom]        *--*--*     <- your customizations

现在您可以执行 git rebase master custom 来根据最新的更改重播您的更改,解决整个过程中的任何冲突。您的时间线将如下所示:

              +-- WordPress 1.0
              |     +-- WordPress 1.1
              v     v
[master] --*--*--*--* 
                     \
[custom]              *--*--*     <- your customizations

更新:为了提供一些基本原理...我喜欢这种解决此问题的方法,因为它在 WordPress 代码和您的自定义代码之间提供了明显的区别。当你获得新版本的 WordPress 时,你真的对“集成”不感兴趣。您有兴趣将自定义项重新应用到新版本的 WordPress。在我看来,重新定制最容易通过 rebase 逐次提交来完成。任何冲突都意味着自定义可能会损坏,因此旧的自定义提交无论如何都是垃圾 - 最好从源头上解决问题并保持更新的历史记录干净。

在更新 master 并重新设置和推送 custom 基础之后,协作者只需根据最新的工作重新设置正在进行的工作。

这只是我的观点,作为一个坚定的变基>合并的支持者。 Git 的美妙之处在于很少有一个正确的答案。只要不断调整,直到找到适合您的东西。

I would suggest keeping your changes in a branch, and rebasing that branch against the latest from WordPress whenever you update. In a rough timeline...

              +-- WordPress 1.0
              v
[master] --*--*
               \
[custom]        *--*--*     <- your customizations

When you want to update WordPress, switch to master and make a new commit with the latest souce (or use git-svn to keep master in sync):

              +-- WordPress 1.0
              |     +-- WordPress 1.1
              v     v
[master] --*--*--*--* 
               \
[custom]        *--*--*     <- your customizations

Now you can do a git rebase master custom to replay your changes against the latest, resolving any conflicts along the way. Your timeline would then look like this:

              +-- WordPress 1.0
              |     +-- WordPress 1.1
              v     v
[master] --*--*--*--* 
                     \
[custom]              *--*--*     <- your customizations

Update: To provide a bit of rationale... I like this approach for this problem because it provides a clear differentiation between code from WordPress and your customizations. When you get a new version of WordPress, you're really not interested in "integration". You're interested in re-applying your customizations to the new version of WordPress. In my view, that recustomization is most easily done commit by commit through a rebase. Any conflicts mean a customization likely broke, so the old customization commit is garbage anyway - better to just fix the problem at its source and keep the updated history clean.

After master is updated and custom is rebased and pushed, the collaborators would just rebase their work-in-progress against the latest.

This is just my opinion, as a firm rebase > merge proponent. The beauty of Git is that there's rarely one right answer. Just keep adjusting until you find something that works for you.

百变从容 2024-10-02 09:49:53

我的一般方法是有两个分支,upstreammaster。创建您的存储库(这将在 master 分支中启动您),签入您使用的上游代码的最新副本,然后使用 创建 upsteram 分支>git 分支上游。另外,创建一个标记来指示您导入的上游版本,例如 git tag wordpress-1.0。我通常为此使用轻量级标签(没有任何注释的标签,基本上只是指向修订版本的指针)。

[wordpress-1.0]               Key: [tag]
v                                  branch
* <- upstream                      * commit
^- master 

现在,当您仍在 master 分支中时,复制您的更改并签入这些更改。您现在有两个分支,upstream 包含原始的上游源代码,以及master 包含您的更改,历史记录显示您对 upstream 所做的更改。

[wordpress-1.0]
v
* <- upstream
 \
  +--* <- master 

master 分支中进行所有修改。

[wordpress-1.0]
v
* <- upstream
 \
  +--*--*--* <- master 

当上游代码的新版本出现时,请检查您的 upstream 分支 (git checkoutupstream),清除除 .git 之外的所有内容目录,然后复制到新的上游版本中。使用 git add -A 暂存上游版本中的所有更改、提交并标记它。

[wordpress-1.0]
|  [wordpress-1.1]
v  v
*--* <- upstream
 \
  +--*--*--* <- master 

现在,查看 master,并合并您的上游更改。此时,您可以选择如何合并,例如采用新的上游版本、采用您的版本或采用合并的更改,就像在正常合并中所做的那样。

[wordpress-1.0]
|  [wordpress-1.1]
v  v
*--*--------+ <- upstream
 \           \
  +--*--*--*--* <- master 

因此,您的所有更改都发生在 master 上,并且所有上游版本都按照原样提交到 upstream。这将使您最容易地准确地看到您的代码与上游版本的不同之处,它将有助于跟踪您已经与上游版本合并的更改,等等。

[wordpress-1.0]
|  [wordpress-1.1]
|  |           [wordpress-2.0]
v  v           v
*--*--------+--*-+ <- upstream
 \           \    \ 
  +--*--*--*--*----*--* <- master 

希望这会有所帮助,如果您还有任何其他问题,请告诉我。

My general approach is to have two branches, upstream and master. Create your repository (which will start you in the master branch), check in the latest copy of the upstream code that you use, and then create the upsteram branch with git branch upstream. Also, create a tag indicating which upstream version you have imported, such as git tag wordpress-1.0. I usually use lightweight tags for this (ones without any annotations, just basically a pointer to a revision).

[wordpress-1.0]               Key: [tag]
v                                  branch
* <- upstream                      * commit
^- master 

Now, while you're still in the master branch, copy your changes in and check those in. You now have two branches, upstream which contains the pristine upstream source, and master which contains your changes, with history showing which changes you have made to upstream.

[wordpress-1.0]
v
* <- upstream
 \
  +--* <- master 

Make all of your modifications in the master branch.

[wordpress-1.0]
v
* <- upstream
 \
  +--*--*--* <- master 

When a new version of the upstream code comes along, check out your upstream branch (git checkout upstream), clear out everything but the .git directory, and copy in the new upstream version. Use git add -A to stage all of the changes in the upstream version, commit it, and tag it.

[wordpress-1.0]
|  [wordpress-1.1]
v  v
*--* <- upstream
 \
  +--*--*--* <- master 

Now, check out master, and merge in your upstream changes. At this point, you can choose how to merge, such as taking the new upstream version, taking your version, or taking merged changes, just like you do in a normal merge.

[wordpress-1.0]
|  [wordpress-1.1]
v  v
*--*--------+ <- upstream
 \           \
  +--*--*--*--* <- master 

So, all of your changes happen on master, and all upstream versions are committed exactly as is to upstream. That will let you see most easily exactly how your code differs from the upstream version, it will help keep track of which changes you've already merged with the upstream version, and so on.

[wordpress-1.0]
|  [wordpress-1.1]
|  |           [wordpress-2.0]
v  v           v
*--*--------+--*-+ <- upstream
 \           \    \ 
  +--*--*--*--*----*--* <- master 

Hope this helps, let me know if you have any further questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文