设置 git 'core.editor'时出现问题



我正试图在我的Mac Os Snow Leopard 10.6.7上设置git,但我在这样做时犯了一些错误。。。

此时,我收到以下警告

$ git config --global core.editor
EDITOR=/usr/bin/vim
error: More than one value for the key core.editor: mate
$ git config --global core.editor open
warning: core.editor has multiple values

我该如何解决?最重要的是,我如何将core.editor设置为TextEdit并使其工作?

附言:我已经读过这个问题了。

最简单的方法是将环境变量EDITOR更改为指向mate。在.bash_profile中添加以下内容:

export EDITOR="/usr/local/bin/mate -w"

并重新启动您的终端会话,或获取.bash_profile

至于您的错误信息:

error: More than one value for the key core.editor: mate

这意味着您在.gitconfig.中添加了多个core.editor行

使用mate ~/.gitconfig修改您的.gitconfig并删除多余的行,或者如果您不介意取消设置所有行,请使用:

git config --global --unset-all core.editor

然后使用

git config --global --add core.editor "/usr/local/bin/mate -w"

则可以将$EDITOR设置为之前设置的值。


如果mate不在/usr/local/bin中,请使用type mate(在bash中,不确定其他shell)找到它的第一个位置


由于您想使用open作为$GIT_EDITOR,因此需要以下内容:

-W  Causes open to wait until the applications it opens (or that were already open) have exited.  Use with the -n flag to allow open to function as an appropriate app for the $EDITOR environment variable.
-n  Open a new instance of the application(s) even if one is already running.

这将适用于:

 git config --global --unset-all core.editor
 git config --global --add core.editor "open -W -n"

以下对我有效:

git config --global core.editor "open -a 'Sublime Text 2' -nW"

使用Mac OSX 10.7.4和Sublime Text 2 Build 2181

注:

我有subl作为别名:

alias subl="/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"

值得一提的是,以下是我解决它的方法:

1) 磨合终端:

sudo ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

这为指向Sublime Text 3应用程序的二进制文件的/usr/local/bin/添加了一个subl别名。现在在终端中运行subl将启动Sublime Text 3应用程序。

2) 磨合终端:

git config --global core.editor "subl -n -w"

这将editor = subl -n -w添加到~/.gitconfig文件的[core]部分。现在,在终端中运行git commit将在新窗口(-n)中启动Sublime Text 3应用程序(subl),命令行将等待(-w),直到保存提交消息。

Sublime官方文本3文档:http://www.sublimetext.com/docs/3/osx_command_line.html

要在win7中实现这一点,请打开c:\users/username/文件夹中的.gitconfig文件,并在双引号外添加以下带有--wait选项的行。

[core]
  editor = 'F:/Program Files/Sublime Text 2/sublime_text.exe' --wait

希望它对win7用户有所帮助

最新更新