Sublime Forum

Difference between revert_hunk and revert_modification

#1

Quoting @deathaxe from https://github.com/jisaacks/GitGutter/issues/558#issuecomment-726201500 saying that

Please also note that ST3207+ also defines key bindings with nearly the same meaning!

{ "keys": ["ctrl+k", "ctrl+z"], "command": "revert_hunk" },
{ "keys": ["ctrl+k", "ctrl+shift+z"], "command": "revert_modification" },

I am wondering if there’s any difference at all between commands revert_hunk and revert_modification?

0 Likes

#2

Sublime Text tracks changes on a per-modification basis, ie. you can have multiple modifications per line. You can jump between modifications using ctrl+. and ctr+,.

Hunks are any number of line-adjacent modifications, like you’d see in a diff.

1 Like

#3

Thank you for your explanation @bschaaf. It’s clear to me now.

revert_modification, together with next_modification and prev_modification, are modification-based. It’s possible to have multiple modifications per line.

In contrast, revert_hunk is always line-based.

To give an example, let’s start with a file

hello, world

and do 3 modifications

Hello, World!
^      ^    ^

Now running next_modification will go through H, W, and ! one by one, and it’s possible to run revert_modification exactly at W to get

Hello, world!

In contrast, running revert_hunk will always give you the original line

hello, world
1 Like