magit 在 emacs 生态里是一大神器,当我们编辑当前项目文件,并且想对当前文件提交 commit 并 push,如何做?很简单使用下面的 aborn/simple-git-commit-push 命令就能达到效果!
(defun aborn/simple-git-commit-push (msg)
"Simple commit current git project and push to its upstream."
(interactive "sCommit Message: ")
(when (= 0 (length msg))
(setq msg (format-time-string "commit by magit in emacs@%Y-%m-%d %H:%M:%S"
(current-time))))
(message "commit message is %s" msg)
(when (and buffer-file-name
(buffer-modified-p))
(save-buffer)) ;; save it first if modified.
(magit-stage-modified)
(magit-commit (list "-m" msg))
(magit-push-current-to-upstream nil))
将上面的 elisp 代码放到你的 init.el 文件里,当想 commit 时,执行:
M-x aborn/simple-git-commit-push
然后跳出一个交互输入:

当输入完 commit 信息后,回车!然后就会做异步的 commit 和 push(不会卡住当前 emacs 操作)。相当于执行了命令行下的以下两个命令:
git commit -am "your message"
git push
注意:

