6

Some commit messages contain sha1 hashes of older commits in order to reference these commits, e.g.:

Fixes: deadbeef

Is it possible to visit the referenced commit from the first commit message?

2
  • 1
    I've created an issue for this (and a bit more): github.com/magit/magit/issues/2949.
    – tarsius
    Commented Jan 10, 2017 at 23:09
  • 1
    This issue was closed on Nov., 9 '17 and the functionality now works out of the box.
    – Gregor
    Commented Apr 23, 2018 at 18:11

2 Answers 2

6

I'm not aware of any builtin command that works on an arbitrary hash at point. You can copy the hash, call C-u magit-show-commit, and then yank the hash.

Instead, I use the following command for this purpose.

(defun km/magit-show-commit-at-point (&optional choose-project)
  "Show commit point.
If there is no current project or if the prefix argument
CHOOSE-PROJECT is non-nil, prompt for the project name."
  (interactive "P")
  (if (save-excursion (skip-chars-backward "A-z0-9")
                      (looking-at "\\b[A-z0-9]\\{4,40\\}\\b"))
      (let* ((hash (match-string-no-properties 0))
             (project
              (and (or choose-project
                       (not (projectile-project-p))
                       (not (magit-rev-verify (concat hash "^{commit}"))))
                   (completing-read "Project: "
                                    (projectile-relevant-known-projects))))
             (default-directory (or project default-directory)))
        (magit-show-commit hash (car (magit-diff-arguments))))
    (user-error "No hash found at point")))

I've written this to work with Projectile. It prompts for a project if the hash doesn't seem to belong to the current project or there is no current project. However, you could easily remove those parts, if you don't use Projectile.

1
  • Thanks, this works, I removed the projectile parts for my usage. It would be nice to work as described by phils, though.
    – Gregor
    Commented Jan 10, 2017 at 22:43
2

This issue was closed on Nov., 9 '17 and the functionality now works out of the box.

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.