在MySQL Workbench文件上的Hg diff [英] hg diff on MySQL Workbench files
问题描述
我正在发布此帖子作为问答,以记录似乎经常出现的问题的解决方法-如何将MySQL Workbench文件置于版本控制下-但我一直无法找到任何解决方案.欢迎提供反馈!
我如何告诉Mercurial将压缩档案的内容diff
,而忽略对这些内容的某些更改?具体来说,如何使用hg
来区分MySQL Workbench(.mwb
)文件的内容,而忽略每次打开该文件时MySQL Workbench进行的许多不重要的更改?我可以使用忽略某些无关更改的自定义脚本吗?
How can I tell Mercurial to diff
the contents of a zipped archive and ignore some of the changes to those contents? Specifically, how can I use hg
to diff the contents of a MySQL Workbench (.mwb
) file, ignoring the many unimportant changes that MySQL Workbench makes every time the file is opened? Can I use a custom script that ignores certain irrelevant changes?
我正在尝试diff
汞储存库中的文件.文件document.mwb.xml
是从.mwb
文件(MySQL Workbench模型文件)中提取的XML文档.基本上,我希望将模型的内容-表结构,可视模型等保持在版本控制下,但不要提交.mwb
文件本身,该文件是zip存档,因此是二进制文件.
I am trying to diff
a file in an hg repository. The file, document.mwb.xml
, is an XML document extracted from a .mwb
file (a MySQL Workbench model file). Basically, I am looking to keep the model's contents—the table structure, visual model, etc.—under version control, but not commit the .mwb
file itself, which is a zip archive and thus a binary file.
每次保存.mwb
文件时,我都会将其解压缩.我将解压缩后的内容保留在我的存储库中,当需要在MySQL中使用.mwb
时再次压缩它们.
Anytime I save the .mwb
file, I unzip it. I keep the unzipped contents in my repository, and just zip them up again when I need to work with the .mwb
in MySQL.
有问题的XML如下:
<?xml version="1.0"?>
<data grt_format="2.0" document_type="MySQL Workbench Model" version="1.4.4">
<value type="object" struct-name="workbench.Document" id="8551CCFA-3AD0-4207-BC76-15ED589CF22C" struct-checksum="0x7131bf99">
<value type="object" struct-name="workbench.logical.Model" id="B48E1CD2-3386-40B7-8E59-AA191598F667" struct-checksum="0xf4220370" key="logicalModel">
<value _ptr_="0x7fbcd1cc3270" type="list" content-type="object" content-struct-name="workbench.logical.Diagram" key="diagrams"/>
<value _ptr_="0x7fbcd1cc3210" type="dict" key="customData"/>
<value _ptr_="0x7fbcd1cc32d0" type="list" content-type="object" content-struct-name="model.Marker" key="markers"/>
<value _ptr_="0x7fbcd1cc3330" type="dict" key="options"/>
<value type="string" key="name"></value>
<link type="object" struct-name="GrtObject" key="owner">8551CCFA-3AD0-4207-BC76-15ED589CF22C</link>
</value>
<value _ptr_="0x7fbcd1cc2b70" type="list" content-type="object" content-struct-name="workbench.OverviewPanel" key="overviewPanels"/>
<value _ptr_="0x7fbcd1cc2c00" type="list" content-type="object" content-struct-name="workbench.physical.Model" key="physicalModels">
<value type="object" struct-name="workbench.physical.Model" id="34B9E967-5C9B-4D1B-8759-C417F6C33AA3" struct-checksum="0x5f896d18">
...
问题是所有这些_ptr_
属性:该文件中实际上有成千上万个属性,并且每次保存文件时,每个属性都会更改,即使没有进行任何修改.结果,对该文件库的完全毫无意义的更改"会使该存储库迅速变得混乱.
The problem is all of those _ptr_
attributes: there are literally thousands of them in this file, and every one of them changes every single time the file is saved, even if nothing is modified. As a result, the repository can rapidly get cluttered with completely meaningless "changes" to this file.
有没有办法使用自定义的diff
例程来忽略这些不相关的更改?
Is there a way to use a custom diff
routine to ignore these irrelevant changes?
推荐答案
I have not found a true solution, but I have developed a satisfactory workaround, inspired by this mwb-diff gist. This allows me to unzip and diff the .mwb
file's contents, commit those contents and their changes to the repository, and use the .mwb
normally when necessary.
我的项目是这样设置的:
My project is set up like this:
project_root
/dist
/schema
/src
/test
我保存了.mwb
文件-在project_root/schema
中将其命名为MyModel.mwb
.显然,您可以使用其他结构,但是您需要相应地修改以下说明.
I save the .mwb
file - call it MyModel.mwb
- in project_root/schema
. Obviously, you can use a different structure, but you will need to modify the instructions below accordingly.
我创建了以下脚本并将其保存在project_root/schema
中:
I created the following scripts and saved them in project_root/schema
:
unpack.sh
#!/bin/bash
# Unzip the model (MyModel.mwb) into a particular directory (project_root/schema/MyModel)
unzip -o MyModel.mwb -d MyModel/
# Replace all _ptr_="...." attributes with _ptr_="xxx"
sed -i presed -E 's/_ptr_="0x[0-9a-f]+"/_ptr_="xxx"/g' MyModel/document.mwb.xml
pack.sh
#!/bin/bash
# This file goes into the directory containing the model contents, zips them up, and saves them as a .mwb model
cd MyModel/
zip -r ../MyModel.mwb ./* -x lock
cd ..
让水星准备好摇滚
我们需要告诉hg
忽略模型(以及所有其他.mwb
文件).另外,当MySQL Workbench打开时,它会将lock
文件添加到.mwb
存档中,我们需要忽略该文件.因此,将这些行添加到您的.hgignore
文件中:
Getting Mercurial Ready to Rock
We need to tell hg
to ignore the model (and all other .mwb
files). Also, when MySQL Workbench is open, it adds a lock
file to the .mwb
archive, which we need to ignore. So, add these lines to your .hgignore
file:
*.mwb
*.mwb.bak
schema/MyModel/lock
关于
data.db
文件的(可选)也请忽略文件中的
data.db
文件(SQLite数据库).mwb
文件.它是一个二进制文件,其中包含任何INSERT
或其他 模型中非创建的SQL语句.通常,我 不要使用MySQL Workbench来完成这些工作;我只用它来创建和 编辑表格,视图等.因此,我将此行添加到了.hgignore
:
An Aside About the
data.db
FileOptionally, also ignore the
data.db
file (a SQLite database) in the.mwb
file. It is a binary file that contains anyINSERT
s or other non-create SQL statements that are part of your model. As a rule, I don't use MySQL Workbench for this stuff; I use it only to create and edit tables, views, etc. So, I added this line to.hgignore
:
schema/MyModel/data.db
如果要跟踪对data.db
文件的更改,则可能需要
修改此解决方法.
If you want to track changes to the data.db
file, you may need to
modify this workaround.
如何使用脚本
如果要修改.mwb
文件,请通过运行上面的pack.sh
从其组件重建它.可以将它添加为钩子,以在您hg pull
,更新等时自动发生,但是我还没有探索过.
How to Use the Scripts
When you want to modify the .mwb
file, rebuild it from its components by running pack.sh
above. This could be added as a hook to happen automatically when you hg pull
, update, etc., but I haven't explored this, yet.
完成.mwb
文件的编辑并要提交更改后,请运行unpack.sh
脚本.如果需要,您可以在系统上设置一个文件监视实用程序,以在文件更改时自动执行此操作,但这超出了此答案的范围.
When you are done editing the .mwb
file and want to commit your changes, run the unpack.sh
script. If you want, you can set up a file-watching utility on your system to do this automatically when the file changes, but that's beyond the scope of this answer.
Mercurial现在非常乐意跟踪您对.mwb
文件内容的更改,而无需跟踪成千上万个毫无用处的_ptr_
属性.另外,当我在Mercurial上使用它时,基本逻辑(和shell脚本)将与git,SVN等一起使用.
Mercurial is now perfectly happy to track changes to the contents of your .mwb
file without tracking thousands of apparently-useless _ptr_
attributes. Also, while I am using this with Mercurial, the basic logic (and the shell scripts) will work with git, SVN, etc.
重要注意事项:据我所知,_ptr_
属性是不相关的.我上面发布的脚本实际上替换了那些属性的内容. _ptr_="0x98a7b3e4"
(或其他)变为_ptr_"xxx"
.根据我的测试,这无关紧要,MySQL Workbench会很乐意使用重构的文件,显然会忽略_ptr_
值. 我可能错了,这些值可能很重要!强烈建议您在依靠我的解决方案之前自己进行测试.
IMPORTANT CAVEAT: As far as I can tell, the _ptr_
attributes are irrelevant. The scripts I have posted above actually replace the contents of those attributes. _ptr_="0x98a7b3e4"
(or whatever) becomes _ptr_"xxx"
. Based on my testing, this doesn't matter, and MySQL Workbench will happily work with the reconstituted file, apparently disregarding the _ptr_
values. I may be wrong, and these values may matter! You are strongly encouraged to test this for yourself before relying on my solution.
这篇关于在MySQL Workbench文件上的Hg diff的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!