本文翻译自:Comparing the contents of two files in Sublime Text
I have two cloned repositories of two very similar open-source projects, which I have been working on in different instances in Sublime Text 2 to arrive at my desired result. 我有两个非常相似的开源项目的克隆存储库,我在Sublime Text 2中的不同实例中一直在努力达到我想要的结果。 Code from both of these projects was used. 使用了这两个项目的代码。 I have been using Git as version control for my project, but have not included the original projects. 我一直使用Git作为我的项目的版本控制,但没有包括原始项目。 Thus, I would like to be able to quickly compare the contents of two files of the original project and compare the differences between them and my project. 因此,我希望能够快速比较原始项目的两个文件的内容,并比较它们与我的项目之间的差异。
I was hoping that Sublime Text 2 would have a "Compare File" feature, but I can't seem to find anything related to it in the settings or online. 我希望Sublime Text 2具有“比较文件”功能,但我似乎无法在设置或在线中找到任何与之相关的内容。 A third-party ST2 package to accomplish this task would also work well. 完成此任务的第三方ST2程序包也可以正常运行。 Is such a task possible to do within the ST2 text editor? 在ST2文本编辑器中可以执行这样的任务吗?
#1楼
参考:https://stackoom.com/question/1kZ0s/比较Sublime-Text中两个文件的内容
#2楼
There are a number of diff plugins available via Package Control. 通过Package Control可以使用许多diff插件 。 I've used Sublimerge Pro , which worked well enough, but it's a commercial product (with an unlimited trial period) and closed-source, so you can't tweak it if you want to change something, or just look at its internals. 我使用过Sublimerge Pro ,它运行得很好,但它是一个商业产品(具有无限的试用期)和封闭源代码,所以如果你想改变一些东西,或者只是看看它的内部结构,你就无法调整它。 FileDiffs is quite popular, judging by the number of installs, so you might want to try that one out. FileDiffs很受欢迎,从安装次数来看,所以你可能想尝试一下。
#3楼
You can actually compare files natively right in Sublime Text. 您实际上可以在Sublime Text中原生地比较文件。
- Navigate to the folder containing them through
Open Folder...
or in a project 通过“Open Folder...
或项目导航到包含它们的Open Folder...
- Select the two files (ie, by holding Ctrl on Windows or ⌘ on macOS) you want to compare in the sidebar 在侧栏中选择要比较的两个文件(即,在Windows上按住Ctrl或在macOS上⌘ )
- Right click and select the
Diff files...
option. 右键单击并选择Diff files...
选项。
#4楼
UPDATE UPDATE
(Given the upvotes, I feel there is a need for a complete step-by-step explanation...) (鉴于赞成票,我觉得需要一个完整的逐步解释...)
- In the Menu bar click on
File
->Open Folder...
在菜单栏中单击File
- >Open Folder...
- Select a folder (the actual folder does not really matter, this step is just to make the
FOLDERS
sidebar available) 选择一个文件夹(实际的文件夹并不重要,这一步只是为了让FOLDERS
边栏可用) - If there is no Side Bar shown yet, make it appear via
View
->Side Bar
->Show Side Bar
如果尚未显示侧栏,请通过View
- >Side Bar
- >Show Side Bar
- Use this
FOLDERS
-titled Side Bar to navigate to the first file you want to compare. 使用此FOLDERS
-titled Side Bar导航到您要比较的第一个文件。 - Select it (click on it), hold down ctrl and select the second file. 选择它(单击它),按住ctrl并选择第二个文件。
- Having two files selected, right click on one of the two and select
Diff Files...
选择两个文件后,右键单击其中一个Diff Files...
并选择Diff Files...
There should be a new Tab now showing the comparison. 现在应该有一个新的Tab显示比较。
Original short answer: 原始简答:
Note that: 注意:
The "Diff files" only appears with the "folders" sidebar (to open a folder: File->Open Folder) , not with "open files" sidebar. “Diff文件”仅与“文件夹”侧栏一起显示(用于打开文件夹:文件 - >打开文件夹),而不是“打开文件”侧栏。
#5楼
Compare Side-By-Side looks like the most convenient to me though it's not the most popular: 比较Side-By-Side看起来对我来说最方便,虽然它不是最受欢迎的:
UPD: I need to add that this plugin can freeze ST while comparing big files. UPD:我需要补充一点,这个插件可以在比较大文件时冻结ST。 It is certainly not the best decision if you are going to compare large texts. 如果你要比较大文本肯定不是最好的决定。
#6楼
UPDATE OCTOBER 2017 I never knew this feature existed in Sublime Text, but the interface appears to have changed slightly from the previous answer - at least on OS X. Here are the detailed steps I followed: 更新2017年10月我从未知道Sublime Text中存在此功能,但界面似乎与之前的答案略有不同 - 至少在OS X上。以下是我遵循的详细步骤:
- In the Menu Bar click File -> Open... 在菜单栏中单击文件 - >打开...
- Navigate to the FOLDER that contains the files to be compared and with the FOLDER selected, click the Open button, this makes the FOLDERS sidebar appear 导航到包含要比较的文件的文件夹以及所选的文件夹,单击打开按钮,这会使FOLDERS侧边栏出现
- In the FOLDERS sidebar, click on the first file to be compared 在FOLDERS侧边栏中,单击要比较的第一个文件
- Hold the Ctrl on Windows or ⌘ on OS X, and click the second file 按住Windows上的Ctrl或OS X上的⌘,然后单击第二个文件
- With both files selected, right click on one and select Diff Files... 选中两个文件后,右键单击一个并选择Diff Files ...
This opens a new tab showing the comparison. 这将打开一个显示比较的新选项卡。 The first file in red, the second in green. 第一个文件是红色,第二个是绿色。