Skip to content

Instantly share code, notes, and snippets.

@danielmartin
Last active September 21, 2020 21:15
Show Gist options
  • Save danielmartin/34bc36dafd8f900de483394087230f48 to your computer and use it in GitHub Desktop.
Save danielmartin/34bc36dafd8f900de483394087230f48 to your computer and use it in GitHub Desktop.
Press "h" in a Magit interactive rebase to change the commit author of some commits. Username completion is provided by the git shortlog.
(defun dm/change-commit-author (arg)
"Change the commit author during an interactive rebase in Magit.
With a prefix argument, insert a new change commit author command
even when there is already another rebase command on the current
line. With empty input, remove the change commit author action
on the current line, if any."
(interactive "P")
(let ((author
(magit-transient-read-person "Select a new author for this commit"
nil
nil)))
(git-rebase-set-noncommit-action
"exec"
(lambda (_) (if author
(format "git commit --amend --author='%s'" author)
""))
arg)))
(define-key git-rebase-mode-map (kbd "h") #'dm/change-commit-author)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment