Skip to content

Instantly share code, notes, and snippets.

@soheil
Last active December 11, 2020 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soheil/92763e03c9a737a1ead96012b7018615 to your computer and use it in GitHub Desktop.
Save soheil/92763e03c9a737a1ead96012b7018615 to your computer and use it in GitHub Desktop.
Git diff by line in Sublime Text

This allows you to simply select the lines and press CMD+L to see the diff. Create a file named git-log.py in your Sublime Packages/User directory with:

import sublime
import sublime_plugin

class GitLogLineCommand(sublime_plugin.WindowCommand):
    def run(self, reverse=False):
        view = self.window.active_view()
        sel = view.sel()[0]
        line_begin = view.rowcol(sel.begin())[0]
        line_end = view.rowcol(sel.end())[0]
        file = view.file_name()
        view.window().run_command('git_raw', {'command': 'git log -L %d,%d:%s' % (line_begin, line_end, file)})

Add in your sublime-keymap

[
  { "keys": ["super+l"], "command": "git_log_line" }
]

This requires the Git plugin to be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment