Show diff hunk sublime text что это
Incremental Diff
Sublime Text includes a built-in diff functionality that tracks changes to files being edited. The diff calculation is incremental, tracking each buffer modification as it is performed. It does not require the file be stored in a version control system, such as Git.
The exact location of each addition, modification and deletion is tracked. This is used to display markers in the gutter, allow navigation between each change, display inline diffs and allow for reverting changes.
Diffs are calculated against the version of the file on disk, but Git repositories can be configured to diff against HEAD, and the API allows files to be diffed against any content.
Diff Markers
The following is an example of diff markers displayed when using the Mariana color scheme:
27 | |
28 | A line that was added |
29 | |
30 | A modified line |
31 | followed by another modified line |
32 | |
33 | The line before this was deleted |
34 |
See the color schemes documentation for information on customizing the colors and width of the diff markers.
Navigation
Users can jump to the next or previous modification using the following methods:
The keyboard shortcuts tend to be a very natural way to jump around a file being edited.
Inline Diffs
In addition to tracking which lines have been modified, the incremental diff also tracks the exact changes. This allows displaying the original version of the text.
Toggling
When right-clicking on a modified region of a file, a menu entry Show Diff Hunk will be available. This menu item will display the previous content inline beneath the current content. Right-clicking again will show a menu item Hide Diff Hunk to hide the inline diff.
Toggling an inline diff may be performed via the Edit Text Toggle Hunk Diff menu.
In addition to menu-based activation, diffs may also be toggled via keyboard shortcut:
To toggle the diff for a region, while hiding all other diffs, press:
Styling
The styles used for displaying inline diffs are automatically generated for color schemes that have not created their own rules. For custom styles, add rules with the following selectors:
Generally each rule will set the background and foreground_adjust properties.
Reverting
A modification may be reverted to the original text by the keyboard shortcut:
Alternatively, the menu Edit Text Revert Modification may be used.
Settings
If the incremental diff functionality should be enabled. Valid values include:
Controls the behavior of incremental diff for files in a Git repository. Valid values include:
Редактирование Sublime Text с момента последнего сохранения
Кажется, он ничего не нашел в Интернете. Часто тратите время на редактирование нескольких текстовых документов в одно и то же время и отсутствие следов, из которых я редактировал. Когда я закрываю, я не всегда уверен, намеренно ли я изменил или случайно отредактировал символ в файле. Было бы здорово иметь функцию, чтобы показывать изменения с момента последнего, за исключением возвышенного текста.
Кажется, такая очевидная необходимость, что я удивлен, что ничего не могу найти в функциях. Я что-то упускаю, или я единственный, кому нужна эта потребность?
ОТВЕТЫ
Ответ 1
В нижней части экрана появится панель, в которой перечислены различия. Нет очевидного способа отклонить панель, но Ctrl + F снова заменит ее панель поиска.
Ответ 2
Здесь будут выделены вкладки с несохраненными изменениями.
Ответ 3
Вы можете использовать плагин «Измененные диапазоны строк», который помещает небольшой маркер желоба для строк с несохраненными изменениями.
Ответ 4
Вы можете установить плагин FileDiffs, который, помимо прочего, даст вам разницу между текущим (отредактированным) файлом и тем, что сохранено на диске.
Ответ 5
Показать несохраненные изменения
Щелчок правой кнопкой мыши в любом месте файла уже давно предоставляет возможность показать все несохраненные изменения.
В нем будут перечислены все изменения в диалоговой области, также используемые для поиска/замены.
Это должно работать для возвышенного текста 2 и 3.
Добавочный Diff
Более поздняя версия Sublime Text 3 добавила функцию Incremental Diff.
Желоб показывает, какие линии изменились.
Это работает как для несохраненных изменений, так и для изменений между сохранением файла или коммитами git.
Он может быть настроен для отображения различий: последняя сохраненная версия (git не нужен), git Head или (через API) любой другой контент.
Показать модификации:
Или вы можете использовать пункт меню:
Edit → Text → Toggle → Hunk Diff
Или ярлыки:
Ctrl + / (на Mac это значок клевера, а не Ctrl)
Или этот вариант ярлыка, который также закроет/скроет все другие различия Hunks
Ctrl + ; (на Mac это значок клевера, а не Ctrl)
Я не знаю пункт меню, чтобы показать все несохраненные изменения.
Пункты меню и ярлыки доступны для навигации между изменениями и отмены отдельных (встроенных) изменений. (см. связанный документ выше для деталей).
незначительные оговорки:
Переход:
Вернуть ломоть:
Это будет действовать только на diff Hunk который находится на месте вашего курсора.
Это не будет иметь никакого эффекта, если ваш курсор не находится в области измененного кода /diff Hunk.
Вот настройки Sublime Text 3, которые управляют функцией увеличения различий:
mini_diff контролирует инкрементную mini_diff /выкл/вкл только для Git)
Допустимые значения включают в себя:
git_diff_target контролирует поведение инкрементной разницы для файлов в репозитории Git
Допустимые значения включают в себя:
Sublime Text edits since last save
Can’t seem to find anything online. Frequently spend time editing multiple text documents at the same time and loose track of which ones I have edited. When I close I am not always sure whether I have purposefully changed or accidentally edited a character in a file. Would be great to have a feature to show the edits since last save for sublime text.
Seems like such an obvious need that I am surprised that I cannot find anything in features. Am I missing something or am I the only one with this need?
5 Answers 5
A pane will show up at the bottom, listing the differences. There isn’t an obvious way to dismiss the pane, but Ctrl + F will replace it with the search pane again.
This will highlight tabs that have unsaved changes.
You may use the «Marking Changed Rows» plugin, which places a small gutter marker for lines with unsaved changes.
You can install the FileDiffs plugin which among other useful things will give you a diff between the current (edited) file and what is saved to disk.
Show Unsaved Changes
Right-clicking anywhere in the file has long provided an option to show all unsaved changes.
It will list all changes in the dialog area also used for find/replace.
This should work for Sublime Text 2 and 3.
Incremental Diff
A more recent version of Sublime Text 3 added an Incremental Diff feature.
The gutter shows which lines have changed.
This works both for unsaved changes, as well as changes between file saves or git commits.
It can be configured to show diffs against: the last saved version (git not needed), git Head, or (via the API) any other content.
Show modifications:
brings up options to:
I’m unaware of a menu item to show all unsaved changes.
Menu Items and Shortcuts are available to navigate between changes, and revert individual (inline) changes. (see linked doc above for details).
minor caveats:
Navigate:
Revert a Hunk:
This will only act on the diff Hunk that is at the location of your cursor.
It will not have any effect if your cursor is not in an area of modified code / diff Hunk.
Here are the Sublime Text 3 SETTINGS that control the Incremental Diff feature:
mini_diff controls the incremental diff functionality (on / off / on for Git only)
Valid values include:
git_diff_target controls the behavior of incremental diff for files in a Git repository
Valid values include:
Git Integration
Sublime Text’s Git integration includes the following components:
Please note: the following documentation discusses the implementation of the Git integration as seen with the Default and Adaptive themes that are included with Sublime Text. Via the theme engine, it is possible for third-party themes to change the visual presentation of information, in which case the following documentation may not be accurate.
Side Bar
Files and folders displayed in the side bar will include a status badge along the right-hand edge, when modified. This includes files and folder in the Folders section of the side bar, along with files in the Open Files section. Ignored files and folders are de-emphasized in the side bar by reducing the opacity of the name.
When the mouse pauses over a status badge, a tool tip will be displayed indicating the status of the file, or in the case of a folder, the status of the contained files and folders.
Status Badge Key
The following table indicates the meaning of each badge. Please note that the color of the badges will be slightly different as they adapt to the closest hue in the active color scheme.
When a folder contains files with multiple statuses, the badge most toward the end of the above list will override all others.
Status Bar
When the focussed file us containing within the working directory of a Git repository, the status bar will contain the name of the current branch, along with the number of files that are untracked, modified, staged or unmerged. The status bar element will look like:
Diff Markers
Sublime Text’s incremental diff functionality ties in with the Git integration. By default, the incremental diff functionality tracks changes to the file since it was last saved, but it is also possible to diff against HEAD.
Here is an example of what the diff markers look like in action, using the Mariana color scheme:
27 | |
28 | A line that was added |
29 | |
30 | A modified line |
31 | followed by another modified line |
32 | |
33 | The line before this was deleted |
34 |
Changing the setting git_diff_target to » head » will modify the diff markers to display a diff versus the version of the file at the Git repository HEAD, as opposed to the version of the file in the working directory.
See the incremental diff documentation for more information and examples, including instructions for viewing inline diffs, navigating between hunks and reverting changes.
Sublime Merge Integration
The Git features available in Sublime Text were derived from work that went into our other product, Sublime Merge. Sublime Merge is a full-featured, blazing-fast Git client built upon the technologies from Sublime Text.
Since editing source code and prose requires different tools and workflows than managing a Git repository, we opted to integrate the most appropriate Git functionality into Sublime Text, but leave more advanced features in Sublime Merge. The following integration points make it easy to jump into the appropriate Git context:
Editor Context Menu
Side Bar Folder Context Menu
Side Bar File Context Menu
Command Palette
Settings
Enables Git integration
Controls the behavior of incremental diff for files in a Git repository. Valid values include:
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. 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. 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. A third-party ST2 package to accomplish this task would also work well. Is such a task possible to do within the ST2 text editor?
10 Answers 10
You can actually compare files natively right in Sublime Text.
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.
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.
UPDATE
(Given the upvotes, I feel there is a need for a complete step-by-step explanation. )
There should be a new Tab now showing the comparison.
Original short answer:
Note that:
(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.
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.
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.
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.
Ways to open a project
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.
The Sidebar must be visible. You can either «View > Side Bar > Show Side Bar» or use the shortcut, Command-K, Command-B.
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.
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.
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. «