wordpress git

tech2022-12-20  64

wordpress git

If you’re a developer who uses WordPress, chances are that you probably try to implement processes in your development workflow into WordPress. One such process is the use of version control. At the very basic level, version control essentially creates checkpoints in your code, allowing you to go back in time if something goes wrong. Arguably, the most popular version control software today is Git.

如果您是使用WordPress的开发人员,那么您很可能会尝试将开发工作流中的流程实施到WordPress中。 这样的过程之一就是使用版本控制。 在最基本的级别上,版本控制实质上在代码中创建检查点,如果出现问题,则可以使您及时返回。 可以说,当今最流行的版本控制软件是Git。

Implementing such a system in WordPress is not difficult. You can create a Git repository to manage your WordPress source code (which is possible only on the self hosted version). Additionally, you can create a database dump and add it to the repository. Commits through time would track changes in your files and database.

在WordPress中实现这样的系统并不困难。 您可以创建一个Git存储库来管理您的WordPress源代码(仅在自托管版本上才可以)。 此外,您可以创建数据库转储并将其添加到存储库。 随着时间的推移,提交将跟踪您的文件和数据库中的更改。

Although Git repositories can be managed through an array of powerful commands on the terminal or GUI clients which do the heavy lifting, we are going to talk about Revisr in this post. Revisr is a plugin which helps you manage your files and databases within the WordPress admin panel.

尽管可以通过终端或GUI客户端上的一系列功能强大的命令来管理Git存储库,但这些操作繁重,但我们将在本文中讨论Revisr 。 Revisr是一个插件,可帮助您在WordPress管理面板中管理文件和数据库。

Note: I suggest you go through an earlier post on the basics of Git to get familiar with the Git related terms that I am going to use in this article.

注意:我建议您阅读有关Git基础知识的较早文章,以熟悉我将在本文中使用的Git相关术语。

入门 (Getting Started)

After installing and activating Revisr, you need to perform certain steps before the plugin does its work. In the admin panel, go to Revisr → Dashboard to initialize the git repository. Once initialized, it asks you to finalize settings (such as the name and email associated with your Git commits), before you can go back to the Dashboard page to commit.

安装并激活Revisr之后,您需要执行某些步骤,插件才能工作。 在管理面板中,转到Revisr→仪表板以初始化git存储库。 初始化后,它会要求您完成设置(例如与Git提交关联的名称和电子邮件),然后才能返回到“仪表板”页面进行提交。

Once you have confirmed settings, check the files that you want to stage for commit (Revisr selects all unstaged files by default) and commit them by adding a message.

确认设置后,检查要暂存的文件(默认情况下,Revisr选择所有未暂存的文件),并通过添加消息来确认它们。

Once you have made changes after a commit (like say, installing a new plugin), you can come back to the dashboard and create a commit again.

提交后进行更改(例如,安装新插件)后,您可以返回仪表板并再次创建提交。

分支您的工作 (Branching Your Work)

One of the most powerful features of Git is the ability to work with branches. The simplest way to understand a branch is to imagine it as a separate workflow. Git also allows you to merge branches.

Git最强大的功能之一就是可以使用分支。 了解分支的最简单方法是将其想象成一个单独的工作流程。 Git还允许您合并分支。

Go to Revisr → Branches to view a list of branches, create, merge or delete them from within the section.

转到Revisr→分支以查看分支列表,在该部分中创建,合并或删除它们。

管理遥控器 (Managing Remotes)

Since Git is a distributed version control software, you may have copies of your repositories on different systems, sometimes on the cloud. In Git, a ‘remote’ is what these copies are called.

由于Git是一种分布式版本控制软件 ,因此您可能在不同的系统(有时在云上)中拥有存储库的副本。 在Git中,这些副本称为“远程”。

If you have a copy of the repository on the cloud (GitHub, BitBucket or GitLab), you can manage the remote using Revisr. Just go to the Remote tab of the Revisr Settings and fill in the details. In this example, I have created a repository on BitBucket (replace [password] with your password).

如果您在云上拥有存储库的副本(GitHub,BitBucket或GitLab),则可以使用Revisr管理远程。 只需转到“修订者设置”的“远程”选项卡,然后填写详细信息。 在此示例中,我在BitBucket上创建了一个存储库(用您的密码替换[password])。

Once you have entered the details of your remote, you can select ‘Push Changes’ under the ‘Quick Actions’ panel on the Revisr Dashboard. In our case, this is how the repository looks once we have pushed the code.

输入遥控器的详细信息后,您可以在Revisr仪表板上的“快速操作”面板下选择“推送更改”。 在我们的例子中,这就是我们推送代码后存储库的外观。

警告 (Warning)

As houghtelin has rightly pointed out in the comments, please take care that your .git directory is not published to production when you are using Revisr. This directory contains some important information and you should definitely make sure it’s inaccessible to the public. There are a few different ways to do this, an easy way is to create an .htaccess file and instruct Apache to deny all requests to that URL.

正如houghtelin在评论中正确指出的那样,请注意在使用Revisr时,.git目录不会发布到生产环境中。 该目录包含一些重要信息,您绝对应确保公众无法访问它。 有几种不同的方法可以执行此操作,一种简单的方法是创建.htaccess文件并指示Apache拒绝对该URL的所有请求。

备份和还原数据库 (Backup and Restoring the Database)

In the introduction, I mentioned taking dumps of the database and attaching them to your regular commits. This is exactly what Revisr does. Before we proceed, you might want to have a look at the database structure of WordPress.

在简介中,我提到了提取数据库转储并将其附加到常规提交中。 这正是Revisr所做的。 在我们继续之前,您可能需要看一下WordPress的数据库结构 。

On the ‘Quick Actions’ panel on the Revisr Dashboard, you will find a ‘Backup Database’ button, which instantly backs up your database by creating dump files and committing it, according to the options set in the ‘Database’ tab of your Revisr Settings. Alternately, you have an option to back your database when you are creating a commit.

在Revisr控制台的“ Quick Actions”面板上,您将找到一个“ Backup Database”按钮,该按钮根据Revisr的“ Database”选项卡中设置的选项,通过创建转储文件并提交来立即备份数据库。设定 或者,您可以选择在创建提交时备份数据库。

An error may occur if the correct path to MySQL is not set in the Revisr Settings. For instance, in MAMP, the path to MySQL is /Applications/MAMP/Library/bin/.

如果在“ Revisr设置”中未设置正确MySQL路径,则可能会发生错误。 例如,在MAMP中,通往MySQL的路径是/Applications/MAMP/Library/bin/ 。

Revisr creates a file for each table that is backed up from the database. Let us push and view the changes on BitBucket.

Revisr为从数据库备份的每个表创建一个文件。 让我们推送并查看BitBucket上的更改。

故障排除 (Troubleshooting)

As you might have observed from the dashboard screenshot above, I was having trouble taking a backup of the database. I debugged the error by finding out that the MySQL path was empty. This was visible in the Help tab of the Revisr Settings page.

正如您可能从上面的仪表板屏幕截图中看到的那样,我在备份数据库时遇到了麻烦。 我通过发现MySQL路径为空来调试错误。 这在“修订者设置”页面的“帮助”选项卡中可见。

The help tab contains certain other information that might help you debugging your problems. You may also check the activity log in your Dashboard to find out what might be causing trouble.

帮助选项卡包含某些其他信息,这些信息可能有助于您调试问题。 您还可以检查仪表板中的活动日志,以找出可能引起麻烦的原因。

最后的想法 (Final Thoughts)

There are many Git plugins for WordPress, and another popular option is VersionPress. While VersionPress focuses on changes on the site, Revisr gives more weightage to the development cycle (which should excite the developers). VersionPress came up with a detailed post on how the two are different.

有许多用于WordPress的Git插件,另一个流行的选项是VersionPress 。 虽然VersionPress着重于网站上的更改,但Revisr却将更多的精力放在开发周期上(这应该使开发人员兴奋)。 VersionPress提出了关于两者的不同的详细文章 。

Yet another version control management system for WordPress is Gitium.

WordPress的另一个版本控制管理系统是Gitium 。

What I mean to say is that whether you are a developer or just another blogger, managing your WordPress site through version control is never a bad idea. Although it might be a bit difficult to get used to, I assure you the benefits in the long run are going to be immense. At least, you wouldn’t be Googling frantically if you drop your database by accident!

我的意思是说,无论您是开发人员还是仅仅是另一个博客作者,通过版本控制管理WordPress网站从来都不是坏主意。 尽管要适应它可能有些困难,但我向您保证,从长远来看,其好处是巨大的。 至少,如果您意外删除数据库,您不会疯狂地搜索!

翻译自: https://www.sitepoint.com/revisr-git-for-wordpress/

wordpress git

相关资源:修订者:修订者:WordPress的Git-源码
最新回复(0)