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?
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?
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.
This issue was closed on Nov., 9 '17 and the functionality now works out of the box.