如何修改 Magit Interactive Rebase 的排列顺序?

请教大家:

Magit Interactive Rebase (M-x magit-dispatch RET r i) 的 commits 排序由上下到为:旧->新,与 git log 的排序相反,不知道有无现成方案把它的排序变为:新->旧?

参考:

  1. Git Interactive Rebase Order is Wrong - Sal Ferrarello
  2. vim插件的实现:vim-interactive-rebase-reverse/ftplugin/gitrebase.vim at master · salcode/vim-interactive-rebase-reverse · GitHub

提供个思路

(defun eli/magit-reverse-rebase-commits ()
  "Reverse the order of commits displayed during a Git interactive rebase."
  (read-only-mode -1)
  (let* ((beg (point-min))
		 (end (save-excursion
				(goto-char beg)
				(re-search-forward "^$"))))
	(reverse-region beg end))
  (read-only-mode 1)
  (add-hook 'with-editor-pre-finish-hook #'eli/magit-reverse-rebase-commits nil t))

(add-hook 'git-rebase-mode-hook #'eli/magit-reverse-rebase-commits)
3 个赞

完美。

感谢大佬。直接修改 region 顺序,学到了。 :smiley:

read-only-mode的设置加到(let ((inhibit-read-only t)) ...) 省出一行。