wordpress git_使用Git的WordPress版本控制

wordpress git

Git

This article is part of a series created in partnership with SiteGround. Thank you for supporting the partners who make SitePoint possible.

本文是与SiteGround合作创建的系列文章的一部分。 感谢您支持使SitePoint成为可能的合作伙伴。

Version control is an integral part of the web development workflow, and it is no less necessary with WordPress sites. However, getting a WordPress site set up with version control, or more specifically, with Git, can be challenging in several ways. Knowing what to commit to your Git repositories and what to ignore can be challenging. Syncing database changes can be similarly so. And WordPress, with its ease of updates and additions straight to live sites, makes it incredibly easy to update the live site directly, disrupting the version control process.

版本控制是Web开发工作流程不可或缺的一部分,对于WordPress网站也是如此。 但是,要在WordPress网站上设置版本控制,或更具体地说,使用Git设置,可能会在多种方面带来挑战。 知道要提交给您的Git存储库的内容以及要忽略的内容可能是具有挑战性的。 同步数据库更改可能与此类似。 WordPress易于直接在实时站点中进行更新和添加,因此可以非常轻松地直接更新实时站点,从而中断了版本控制过程。

Below are a few options for using Git with WordPress, some information about VersionPress, the well known Git plugin, as well as a brief mention of hosting-based Git implementations.

以下是将Git与WordPress结合使用的一些选项,有关VersionPress(著名的Git插件)的一些信息,以及对基于托管的Git实现的简要说明。

在WordPress中使用Git (Using Git with WordPress)

Using Git with WordPress can be a challenge. Here are a few tips that can get you going the right direction (note that these tips are assuming you already have a basic familiarity with Git):

在WordPress中使用Git可能是一个挑战。 这里有一些技巧,可以帮助您朝正确的方向发展(请注意,这些技巧是假设您已经对Git有了基本的了解):

Regarding your database connection, you should do one of two things: Either use the same exact database name and credentials in development, staging, and production environments, so that there is no difference in your wp-config.php database connection info, or else .gitignore your wp-config.php entirely so that it doesn’t get overwritten with the info from your local development environment.

关于数据库连接,您应该执行以下两项操作之一:在开发,登台和生产环境中使用相同的确切数据库名称和凭据,以使wp-config.php数据库连接信息没有区别,否则.gitignore完全.gitignore您的wp-config.php以免被您本地开发环境中的信息所覆盖。

Speaking of things to ignore, you should also probably .gitignore your uploads directory. It’s unnecessary to be syncing uploads, and uploads are the one thing that may be added to the production file system only, so no need to cause unnecessary sync problems!

说到要忽略的事情,您可能还应该.gitignore上传目录。 不必同步上传,上传是仅可以添加到生产文件系统的一件事,因此无需引起不必要的同步问题!

Disabling certain abilities within WordPress can be useful as well.

禁用WordPress中的某些功能也可能很有用。

  • Disable automatic updates by adding define( 'AUTOMATIC_UPDATER_DISABLED', true ); to wp-config.php. This will stop the automatic updates from occurring altogether on the productions site.

    通过添加define( 'AUTOMATIC_UPDATER_DISABLED', true );禁用自动更新define( 'AUTOMATIC_UPDATER_DISABLED', true );wp-config.php 。 这将停止在生产站点上完全进行自动更新。

  • Disable the admin panel’s file editor by adding define( 'DISALLOW_FILE_EDIT', true ); to prevent it from being used to modify theme code and other files on the production site.

    通过添加define( 'DISALLOW_FILE_EDIT', true );禁用管理面板的文件编辑器define( 'DISALLOW_FILE_EDIT', true ); 以防止其被用来在生产站点上修改主题代码和其他文件。

  • Or, stop themes, plugins, etc from being modified or added at all (rendering the previous wp-config.php suggestions unnecessary) on production with define( 'DISALLOW_FILE_MODS', true );. This ensures that all updates are first done in a development or staging environment, and then pushed manually to the live site.

    或者,在生产环境中使用define( 'DISALLOW_FILE_MODS', true );停止修改或添加主题,插件等(无需提供先前的wp-config.php建议define( 'DISALLOW_FILE_MODS', true ); 。 这样可以确保首先在开发或登台环境中完成所有更新,然后手动将其推送到实时站点。

  • Note that usage of any of these restrictions should be coupled with creating a process to ensure that updates are regularly performed. Automatic updates exist for a reason, and if you don’t ensure your sites are up to date, you’re making them less vulnerable from one type of risk and more to another.

    请注意,使用这些限制中的任何一项都应与创建流程以确保定期执行更新相结合。 存在自动更新是有原因的,如果您不确保自己的网站是最新的,则将使它们免受一种风险的危害较小,而使另一种风险的危害更大。

Backups created manually or by plugins should be stored somewhere outside of the Git repository (preferably to an offsite or cloud backup).

手动或通过插件创建的备份应存储在Git存储库之外的某个位置(最好是异地或云备份)。

使用VersionPress (Using VersionPress)

VersionPress is an alternative to traditional Git repository usage with WordPress websites. Installing VersionPress is as easy as any other plugin! As part of the installation process, VersionPress will check the prerequisites that it requires on the host system, and warn you or stop the installation if they are not present.

VersionPress是WordPress网站使用传统Git存储库的替代方法。 安装VersionPress与其他任何插件一样简单! 在安装过程中,VersionPress将检查主机系统上所需的先决条件,并警告您或停止安装(如果不存在)。

Once you’ve got it installed, you’re good to go! VersionPress tracks every change to the site – added, modified, and deleted posts or pages, plugin changes, etc. You can see a list of tracked events, and you can click “Undo” next to any single event to undo that specific past event, or you can click “Roll Back” to roll the entire site back to the state that it was in at the time of that event. Pretty cool!

一旦安装完成,那就好了! VersionPress跟踪对站点的所有更改-添加,修改和删除的帖子或页面,插件更改等。您可以查看已跟踪事件的列表,并且可以单击任何单个事件旁边的“撤消”来撤消该特定过去的事件,也可以单击“回滚”将整个站点回滚到该事件发生时的状态。 太酷了!

On top of all of that, power users can use their normal Git client to manage the VersionPress install, since every action and command that VersionPress performs is powered directly by Git.

最重要的是,高级用户可以使用其普通的Git客户端来管理VersionPress的安装,因为VersionPress执行的每个操作和命令都直接由Git驱动。

主机提供的Git服务 (Host Provided Git Services)

Some hosts provide their own version control services, allowing WordPress admins to benefit from the use of Git repositories to control their site, without having to set up a repository somewhere and maintain it. SiteGround , for one, uses a Git powered cPanel plugin to offer version control services from right within your cPanel, making it very easy to use.

一些主机提供了自己的版本控制服务,使WordPress管理员可以受益于使用Git存储库来控制其站点,而无需在某个地方设置存储库并进行维护。 例如,SiteGround使用Git驱动的cPanel插件从cPanel内部直接提供版本控制服务 ,使其非常易于使用。

No matter what you choose, version control is still very achievable for WordPress admins, and it’s the best way to keep your site updated, safe, and easy to manage!

无论您选择哪种方式,对于WordPress管理员来说,版本控制仍然非常容易实现,这是保持网站更新,安全和易于管理的最佳方法!

翻译自: https://www.sitepoint.com/wordpress-version-control-git/

wordpress git