I am reading a diff between two revisions, say A..B, possibly limited to a single file.

Once in a while, I stumble on a hunk that I’d like to investigate in detail. I want to press a key or two and see the commit(s) that introduce the change I’m currently looking at.

Since that is kind of vague, let’s say I want the equivalent of l =L file RET start,+lines RET l range RET, where file, start and lines are taken from the current hunk and range is the current diff’s range. The log should not be limited to the file, even if the diff was.

I can do this manually but I want to automate it.

2 Answers 2


That's currently not supported. There already exist requests for similar features and I plan to implement such things eventually. So it's not strictly necessary that you open a feature request for this, but if you want to really make sure I don't forget about this particular variant, then you might want to open one anyway.


As a stopgap, I’m going to try this:

(defun yk-magit-log-hunk ()
  (let ((yk-diff-range (car magit-refresh-args)))
      ('hunk (let* ((yk-file (magit-section-value (magit-section-parent it)))
                    (yk-hunk-lines (nth 2 (magit-section-value it)))
                    (yk-line-range (replace-regexp-in-string
               (magit-log (list yk-diff-range)
                          (list (concat "-L" yk-line-range ":" yk-file))
      ('file (let ((yk-file (magit-section-value it)))
               (magit-log (list yk-diff-range) nil (list yk-file)))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.