Comparing the contents of two files in Sublime Text

前端 未结 10 1939
被撕碎了的回忆
被撕碎了的回忆 2021-01-29 17:27

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. Co

相关标签:
10条回答
  • 2021-01-29 17:39

    UPDATE JAN 2018 - especially for Sublime/Mac

    (This is very similar to Marty F's reply, but addresses some issues from previous responses, combines several different suggestions and discusses the critical distinction that gave me problems at first.)

    I'm using Sublime Text 3 (build 3143) on Mac and have been trying for about 30 minutes to find this File Compare feature. I had used it before on Sublime/Mac without any problems, but this time, it was trickier. But, I finally figured it out.

    1. The file format does not need to be UTF-8. I have successfully compared files that are UTF-8, ISO-8559-1, and Windows-1252.

    2. There is no File > Open Folders on Sublime/Mac. Many instructions above start with "Select File > Open Folders," but that doesn't exist on Sublime/Mac.

    3. File compare works on a Project basis. If you want to compare two files, they must be saved to disk and part of the current project.

    4. Ways to open a project

    • If Sublime/Mac is not running or if it's running but no windows are open, drag a folder onto the Sublime app.
    • If Sublime/Mac is running, select "File > Open", navigate to the desired folder, don't select a file or folder and click "Open".
    1. Add a folder to a project. If the files you want to compare are not part of the same hierarchy, first open the folder containing one of the files. Then, select "Project > Add Folder to Project", navigate to the folder you want and click "Open". You will now see two root-level folders in your sidebar.

    2. The Sidebar must be visible. You can either "View > Side Bar > Show Side Bar" or use the shortcut, Command-K, Command-B.

    3. Files must be closed (ie, saved) to compare. Single-clicking a file in the Side Bar does not open the file, but it does display it. You can tell if a file is open if it's listed in the "Open Files" section at the top of the Side Bar. Double-clicking a file or making a modification to a file will automatically change a file's status to "Open". In this case, be sure to close it before trying to compare.

    4. Select files from the folder hierarchy. Standard Mac shorcut here, (single) click the first file, then Command-click the second file. When you select the first file, you'll see its contents, but it's not open. Then, when you Command-click the second file, you'll see its contents, but again, neither are open. You'll notice only one tab in the editing panel.

    5. Control-click is not the same as right-click. This was the one that got me. I use my trackpad and often resort to Control-click as a right-click or secondary-click. This does not work for me. However, since I configured my trackpad in System Preferences to use the bottom-right corner of my trackpad as a right-click, that worked, displaying the contextual menu, with "Delete", "Reveal in Finder", and.... "Diff Files..."

    Voilà!

    0 讨论(0)
  • 2021-01-29 17:40

    View - Layout and View - Groups will do in latest Sublime 3

    eg:

    Shift+Alt+2 --> creates 2 columns

    Ctrl+2 --> move selected file to column 2

    This is for side by side comparison. For actual diff, there is the diff function other already mentioned. Unfortunately, I can't find a way to make columns scroll at the same time, which would be a nice feature.

    0 讨论(0)
  • 2021-01-29 17:44

    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...
    2. Select a folder (the actual folder does not really matter, this step is just to make the FOLDERS sidebar available)
    3. If there is no Side Bar shown yet, make it appear via View -> Side Bar -> Show Side Bar
    4. Use this FOLDERS-titled Side Bar to navigate to the first file you want to compare.
    5. Select it (click on it), hold down ctrl and select the second file.
    6. Having two files selected, right click on one of the two and select Diff Files...

    There should be a new Tab now showing the comparison.


    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.

    0 讨论(0)
  • 2021-01-29 17:50

    Compare Side-By-Side looks like the most convenient to me though it's not the most popular:

    UPD: I need to add that this plugin can freeze ST while comparing big files. It is certainly not the best decision if you are going to compare large texts.

    0 讨论(0)
  • 2021-01-29 17:51

    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:

    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
    3. In the FOLDERS sidebar, click on the first file to be compared
    4. Hold the Ctrl on Windows or ⌘ on OS X, and click the second file
    5. With both files selected, right click on one and select Diff Files...

    This opens a new tab showing the comparison. The first file in red, the second in green.

    0 讨论(0)
  • 2021-01-29 17:53

    There are a number of diff plugins available via Package Control. 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. FileDiffs is quite popular, judging by the number of installs, so you might want to try that one out.

    0 讨论(0)
提交回复
热议问题