I've noticed some repositories use 7 characters, others 11 when displaying a SHA1.

It looks as if magit uses the output of git log --pretty=oneline --abbrev-commit however I can't see how to configure this to behave differently.

Incomplete Solutions

Call with arguments

If I call (magit-log-current nil (list "--abbrev=12")) then the log shows at least 12 characters. However refreshing the log view looses the setting.

Set the initial arguments

This also works before refreshing resets the value and looses the SHA1 length I had set.

(put 'magit-log-mode 'magit-log-current-arguments
     (cons "--abbrev=12" (get 'magit-log-mode 'magit-log-default-arguments)))
(call-interactively 'magit-log-current)

Is there a way to control how many characters I used to display the SHA1 hash in Magit's log view?

2 Answers 2


Note that using advice isn't ideal, however I couldn't find a way to do this that didn't involve changing my personal git configuration.

This can be done by adding advice to magit-log-arguments.

(defvar my-magit-log-sha1-size 16)
(defun my-magit-log-arguments-extra (fn-orig &optional mode)
  (pcase-let ((`(,args ,files) (funcall fn-orig mode)))
    (list (append args (list (format "--abbrev=%d" my-magit-log-sha1-size))) files)))

(advice-add 'magit-log-arguments :around #'my-magit-log-arguments-extra)

In a shell, do

git config --global core.abbrev 12

or use --local to set it per project.

You'll have to recreate the log buffer to enable the change.

  • Is there a way to do this that only impacts magit? This is needed for a package I maintain and I don't want users of this package to have to modify their local git configuration.
    – ideasman42
    Jan 24, 2022 at 5:10
  • I don't know much about magit (although you seem to have found a way to do it). OTOH, you can do --local to have it done per project, rather than globally.
    – NickD
    Jan 24, 2022 at 13:31

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.