mercurial使用
Since we have presented a way to review the history of committed changes using Git, Team Foundation Server and Subversion, let’s check how the same can be achieved when working with the Mercurial source control system.
由于我们提供了一种使用Git , Team Foundation Server和Subversion来查看已提交更改的历史的方法,因此让我们检查一下在使用Mercurial源代码控制系统时如何实现相同的更改。
We’ll be using Tortoise Hg, free Mercurial client that comes with Windows shell integration. For the purpose of this article we’ll use a sample database called StoresDB whose objects are scripted in separate files and saved in a local folder called MercLocal. The same folder is initialized to be a local Mercurial repository. I won’t include details about initializing the repository and committing changes. The goal of the article is to cover the following: revision history of all committed changes, comparing two versions of the same object committed in two different changesets and getting specific version of an object from the commit history.
我们将使用Windows Shell集成随附的免费Mercurial客户端Tortoise Hg 。 就本文而言,我们将使用一个名为StoresDB的示例数据库,该数据库的对象被编写在单独的文件中,并保存在名为MercLocal的本地文件夹中。 相同的文件夹被初始化为本地Mercurial存储库。 我不会提供有关初始化存储库和提交更改的详细信息。 本文的目的是涵盖以下内容:所有已提交更改的修订历史记录,比较在两个不同变更集中提交的同一对象的两个版本,并从提交历史记录中获取对象的特定版本。
As a starting point, let’s assume that the following tasks were performed against previously scripted database object files:
首先,假设对先前编写脚本的数据库对象文件执行了以下任务:
Initial commit of all database objects
初始提交所有数据库对象
Committing a new table called Balances using the following SQL script:
使用以下SQL脚本提交一个名为Balances的新表:
CREATE TABLE [dbo].[Balances]([BalanceID] [varchar](15) PRIMARY KEY NOT NULL,[Description] [varchar](255) NULL,[DocID] INT IDENTITY(1,1) NOT NULL)GO
In the next changeset the following changes are committed:
在下一个变更集中,将进行以下更改:
New column called BalanceType is added to the Balances table using the following SQL script:
使用以下SQL脚本,将称为BalanceType的新列添加到Balances表中:
ALTER TABLE dbo.Balances ADD BalanceType NVARCHAR(50)
New stored procedure called BalancesList is created using the following script:
使用以下脚本创建名为BalancesList的新存储过程:
CREATE PROCEDURE dbo.BalancesList
AS
BEGIN
SELECT BalanceID, Description, DocID FROM dbo.Balances
END
GO
New column added to the ProductCategory table:
新列添加到ProductCategory表:
ALTER TABLE Production.ProductCategoryADD CategoryDescription NVARCHAR (255)
The next changeset holds just a single edit. The previously created BalanceType column in the Balances table is renamed using the following script:
下一个变更集仅包含一个编辑。 使用以下脚本重命名了Balances表中先前创建的BalanceType列:
EXEC sp_rename 'dbo.Balances.BalanceType', 'BType', 'COLUMN'
The last change we committed is deleting the Sales.CreditCard table:
我们提交的最后一个更改是删除Sales.CreditCard表:
DROP TABLE Sales.ShoppingCartItem;
In order to review the entire history of committed changes, start the TortoiseHg Workbench application. It can be started from the right click menu inside the folder initialized as a local Mercurial repository (in this case the MercLocal folder):
为了查看已提交更改的整个历史记录,请启动TortoiseHg Workbench应用程序。 可以从初始化为本地Mercurial存储库(在此情况下为MercLocal文件夹)的文件夹内的右键单击菜单中启动:
As shown in the above image, the history view presents the task workflow introduced in the article. The first commit (at the bottom of the list) shows initial commit of all database objects, followed by commits where the rest of changes are committed.
如上图所示,历史视图显示了本文介绍的任务工作流程。 第一个提交(在列表的底部)显示所有数据库对象的初始提交,然后显示提交其余更改的提交。
Each commit in the list contains the revision ID (the Rev column), branch where it is committed (currently all changes are committed to default branch), description – which is actually the commit message, the author of the commit (all commits are performed by the same user – ApexSQL Test). The Age column stores the time that passed after the commit is performed. The Changes column at the end, shows the exact number of changes included in the specific changeset, along with the appropriate colors that represents the actions performed against committed files:
列表中的每个提交都包含修订ID(“ 修订”列),提交的分支(当前所有更改都提交给默认分支),描述(实际上是提交消息),提交的作者(执行所有提交)由同一用户-ApexSQL测试)。 “ 年龄”列存储执行提交后经过的时间。 最后的“ 更改”列显示特定更改集中包含的确切更改数量,以及代表针对已提交文件执行的操作的适当颜色:
The above described comparison between revisions gives a list of all objects that are compared, so the user can select which one to inspect in details, as we did for the dbo.Balances table. In case we need to inspect differences for the specific object across revision history, there is no need to compare all objects from one changeset with all objects from another changeset. To narrow down the comparison to a single object, select it from the list of objects in any changeset, and from the right click menu select the Compare File Revisions option. We’ll perform that against the dbo.Balances table from the Rev 2 revision:
修订之间的上述比较给出了所有比较对象的列表,因此用户可以选择要详细检查的对象,就像我们对dbo.Balances表所做的那样 。 如果我们需要检查整个修订历史中特定对象的差异,则无需将一个变更集的所有对象与另一变更集的所有对象进行比较。 要将比较范围缩小到单个对象,请从任何变更集中的对象列表中选择它,然后从右键单击菜单中选择“ 比较文件修订”选项。 我们将针对Rev 2修订版中的dbo.Balances表执行该操作:
This initiates the Log file viewer form for the selected object. Both sides, left and right, shows the same list of revisions related to specific object (in this case the Balances table). To compare between revisions, simply select one on the left side, and another one on the right (we’ll compare the version of the balances table from Rev 1 with the version from Rev 3):
这将启动所选对象的日志文件查看器表单。 左右两侧都显示与特定对象相关的相同修订版本列表(在本例中为“ 余额”表)。 要在修订版本之间进行比较,只需在左侧选择一个,在右侧选择另一个(我们将比较Rev 1中的余额表版本和Rev 3中的版本):
The above image shows that the BType we have introduced in Rev3 didn’t exist in Rev 1 when the Balances table was committed initially.
上图显示的是BTYPE我们Rev3型已经介绍,当余额表最初承诺没有在版本1存在。
In case the entire revision needs to be reverted, right click on it from the revision history and select the Revert All Files option:
如果需要还原整个修订,请在修订历史中右键单击它,然后选择“ 还原所有文件”选项:
Reverting to Rev 1 discards all changes committed after the Rev 1. This means that BalancesList stored procedure will be deleted, as well as BType column that was committed in the later revision. Checking the Balances table in the local repository gives the following result:
恢复到修订版1会丢弃在修订版1之后提交的所有更改。 这意味着将删除BalancesList存储过程以及在更高版本中提交的BType列。 检查本地存储库中的余额表将得到以下结果:
This confirms that the BalanceType column introduced in the next revision, and renamed to BType later, does not exist.
这确认了在下一个修订版中引入并在以后重命名为BType的BalanceType列不存在。
In case only specific object(s) need to be reverted, instead of the entire revision, navigate to the specific revision, select one (or multiple files using the CTRL key), and from the right click menu select the Revert to Revision option:
如果只需要还原特定对象而不是整个修订版本,请导航至该特定修订版本,选择一个(或使用CTRL键的多个文件),然后从右键单击菜单中选择“ 还原为修订版本”选项:
The above image represents reverting the version of the Balances table from Rev 2, without reverting other changes from the same revision. Selecting the Revert to Revision option from the right click menu gives a confirmation dialog, where optionally all object from the selected revision can be reverted (by checking the Revert all files to this revision option). In order to demonstrate reverting of a single object, this option will be unchecked:
上面的图像表示从修订版2还原余额表的版本,而未还原同一修订版的其他更改。 从右键单击菜单中选择“ 还原到修订版本”选项,将显示一个确认对话框,在该对话框中,可以选择还原来自选定修订版本的所有对象(通过选中“将所有文件还原到此修订版本”选项)。 为了演示单个对象的还原,将不选中此选项:
After clicking the OK button, to confirm reverting just the Balances table, let’s inspect the local repository.
单击“ 确定”按钮后,要确认仅还原“ 余额”表,让我们检查本地存储库。
The Balances table is shown as changed, and reviewing the actual script shows that BType column committed in Rev 4 is reverted back to BalanceType committed in Rev 2:
余额表显示为已更改,并且查看实际脚本后发现, 修订版4中提交的BType列已还原为修订版2中提交的BalanceType :
Also, BalancesList stored procedure still exists in the local repository since we have reverted the Balances table only.
另外,由于我们仅还原了Balances表,因此BalancesList存储过程仍存在于本地存储库中。
Using this approach, any revision can be reverted, which will actually revert all files from the revision, or selecting specific object(s) from the revision can be reverted without affecting the rest of changes from the revision.
使用此方法,可以还原任何修订,这实际上将还原该修订中的所有文件,或者可以还原从该修订中选择特定的对象,而不影响该修订的其余更改。
To see the full version history of a SQL Server database object under source control, you can try ApexSQL Source Control, an SSMS add-in that allows you to put a database under version control, commit all changes to the repository and easily revert any committed change from the history.
要查看在源代码管理下SQL Server数据库对象的完整版本历史记录 ,可以尝试ApexSQL Source Control,它是一种SSMS加载项,可让您将数据库置于版本控制下 ,将所有更改提交到存储库并轻松还原任何已提交改变历史。
翻译自: https://www.sqlshack.com/revision-history-object-change-sql-database-using-mercurial/
mercurial使用