简体   繁体   English

设置为 Git 编辑器时退出 emacsclient 的正确方法

[英]Correct Way to Exit emacsclient When Set as the Git Editor

I'd like to use emacsclient as my editor in git, ie the core.editor setting in my .gitconfig .我想在 git 中使用 emacsclient 作为我的编辑器,即我的.gitconfig中的core.editor设置。 In my .gitconfig , I have:在我的.gitconfig中,我有:

...
[core]
  editor = /usr/local/bin/emacsclient --tty
...

When I do something like git commit --amend , or just git commit , I get put into emacs(client) as expected, but when trying to exit with Cx Cc , I get the message:当我执行git commit --amendgit commit之类的操作时,我按预期进入了 emacs(client),但是当我尝试使用Cx Cc退出时,我收到消息:

Don’t kill this buffer #<buffer COMMIT_EDITMSG>.  Instead cancel using C-c C-k

Following the suggestion to cancel above results in an obvious error from git:按照上面的建议取消会导致来自 git 的明显错误:

error: There was a problem with the editor '/usr/local/bin/emacsclient --tty'.
Please supply the message using either -m or -F option.

What I've discovered is that using Cx # kind of works, my changes are there.我发现的是,使用Cx #作品,我的更改就在那里。 However, the next time I run something like git commit --amend , I get the message in emacsclient:但是,下次我运行类似git commit --amend的命令时,我在 emacsclient 中收到消息:

Revert buffer from file /[CONTAINING FOLDER]/.git/COMMIT_EDITMSG? (yes or no)

so I'm guessing this isn't exactly the right way to exit.所以我猜这不是正确的退出方式。 I've also tried Cx k , but that doesn't seem to save anything.我也试过Cx k ,但这似乎没有保存任何东西。

Looks like the buffer is using (one of the variants of) git-commit mode.看起来缓冲区正在使用(其中一种变体) git-commit模式。

To accept the commit message use Cc Cc (control+c twice)要接受提交消息,请使用Cc Cc (control+c 两次)

https://github.com/magit/magit/blob/main/lisp/git-commit.el has this commentary: https://github.com/magit/magit/blob/main/lisp/git-commit.el有这样的评论:

 ;; ;; By making use of the `with-editor' package this package provides;;通过使用 `with-editor' package 这个 package 提供;; both ways of finish an editing session. In either case the file;;完成编辑 session 的两种方式。无论哪种情况,文件;; is saved, but Emacseditor's exit code differs.已保存,但 Emacseditor 的退出代码不同。 ;; ;; ;; ;; Cc Cc Finish the editing session successfully by returning;;抄送 抄送 编辑成功 session 返回;; with exit code 0. Git then creates the commit using;;退出代码为 0。Git 然后使用创建提交;; the message it finds in the file.它在文件中找到的消息。 ;; ;; ;; ;; Cc Ck Aborts the edit editing session by returning with exit;; Cc Ck 通过返回 exit 中止编辑 session;; code 1. Git then aborts the commit.代码 1. Git 然后中止提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM