我决定使用magit而不是外部的工具或者命令行来管理git项目。我每天基本上都会将emacs 一直开着,但提交,添加等等的时候都是切换到命令行或者使用tortoisegit来进行后续操 作,感觉很不方便,看到很多人推荐magit,就决定试一试。试用下来,果然强大。下面是 我的简单配置:
(add-to-list 'load-path (concat emacs-config-dir "plugin/magit")) (add-to-list 'load-path (concat emacs-config-dir "plugin/git-modes")) (defun magit-escape-for-shell (str) (if (or (string= str "git") (string-match "^--" str)) str (concat "'" (replace-regexp-in-string "'" "'\\''" str) "'"))) (require 'magit) (defun my-git-commit-hook () (auto-fill-mode) (set-buffer-file-coding-system 'utf-8-unix)) (add-hook 'magit-mode-hook 'my-git-commit-hook) (add-hook 'magit-status-mode-hook 'my-git-commit-hook) (defun my-git-commit-signoff-hook () (auto-fill-mode) (git-commit-signoff) (set-buffer-file-coding-system 'utf-8-unix)) (add-hook 'git-commit-mode-hook 'my-git-commit-signoff-hook) ;平台路径相关配置,下面是指定git命令路径的 ;(setq magit-git-executable "C:/Program Files/Git/bin/git.exe") ; 下面这行是放在我的.emacs文件中,所有自己用的emacs的配置都放在一个特定的文件夹中,这样便于管理 ;(setq emacs-config-dir "~/emacs_config/")
上述代码的两个hook,第二个只比第一个多了个git-commit-signoff,因为我想在每次提交 的时候都添加上 酷酷 的 Signed-off-by,如果不想添加的话,可以只使用一个。
关于编码的问题,因为我大部分的配置都是utf-8编码,而在windows上总是乱码,于是指定 编码了。但在打开magit-status的时候还是乱码,不过在提交了之后,magit-status自动刷 新后,却又变成正常的了。不擅长lisp,不知道原因