比较Sublime Text中两个文件的内容

本文介绍了如何在Sublime Text 2中比较两个文件的内容,包括使用内置功能和第三方插件如Sublimerge Pro、FileDiffs。通过侧边栏选择文件并右键点击,选择“Diff Files”选项,或者使用菜单栏打开文件夹后选择文件进行比较。此外,还提到了比较插件可能存在的问题,如在大文件比较时可能会导致编辑器冻结。
摘要由CSDN通过智能技术生成

本文翻译自: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中原生地比较文件。

  1. Navigate to the folder containing them through Open Folder... or in a project 通过“ Open Folder...或项目导航到包含它们的Open Folder...
  2. Select the two files (ie, by holding Ctrl on Windows or on macOS) you want to compare in the sidebar 在侧栏中选择要比较的两个文件(即,在Windows上按住Ctrl或在macOS上
  3. Right click and select the Diff files... option. 右键单击并选择Diff files...选项。

gGzaG.png


#4楼

UPDATE UPDATE
(Given the upvotes, I feel there is a need for a complete step-by-step explanation...) (鉴于赞成票,我觉得需要一个完整的逐步解释...)

  1. In the Menu bar click on File -> Open Folder... 在菜单栏中单击File - > Open Folder...
  2. Select a folder (the actual folder does not really matter, this step is just to make the FOLDERS sidebar available) 选择一个文件夹(实际的文件夹并不重要,这一步只是为了让FOLDERS边栏可用)
  3. If there is no Side Bar shown yet, make it appear via View -> Side Bar -> Show Side Bar 如果尚未显示侧栏,请通过View - > Side Bar - > Show Side Bar
  4. Use this FOLDERS -titled Side Bar to navigate to the first file you want to compare. 使用此FOLDERS -titled Side Bar导航到您要比较的第一个文件。
  5. Select it (click on it), hold down ctrl and select the second file. 选择它(单击它),按住ctrl并选择第二个文件。
  6. 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上。以下是我遵循的详细步骤:

  1. In the Menu Bar click File -> Open... 在菜单栏中单击文件 - >打开...
  2. 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侧边栏出现
  3. In the FOLDERS sidebar, click on the first file to be compared 在FOLDERS侧边栏中,单击要比较的第一个文件
  4. Hold the Ctrl on Windows or ⌘ on OS X, and click the second file 按住Windows上的Ctrl或OS X上的⌘,然后单击第二个文件
  5. 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. 第一个文件是红色,第二个是绿色。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值