设置 git 'core.editor' 时遇到问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6435246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:35:36  来源:igfitidea点击:

Trouble on setting the git 'core.editor'

gitmacoseditorwarningsosx-snow-leopard

提问by user502052

I am trying to set git on my Mac Os Snow Leopard 10.6.7but I made some errors on doing that...

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

At this time I have the following warning:

此时我有以下警告

$ 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

How can I solve that? And, mostly, how can I set the core.editorto TextEdit and make it works?

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

P.S.: I already read this question.

PS:我已经阅读了这个问题

回答by X-Istence

The easiest way is to change the environment variable EDITOR to point to mate. In your .bash_profileadd the following:

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

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

and re-start your terminal session, or source the .bash_profile.

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

As for your error message:

至于你的错误信息:

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

it means you've added multiple core.editor lines in your .gitconfig.

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

Use mate ~/.gitconfigto modify your .gitconfigand remove the extra lines, or if you don't mind unsetting all of them use:

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

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

Then use

然后使用

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

then you can leave $EDITORset to what it was previously set to.

然后您可以将$EDITOR设置保留为之前设置的设置。



If mateis not located in /usr/local/binfind where it is first by using type mate(in bash, not sure about other shells)

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



Since you want to use openas your $GIT_EDITORyou will need the following:

由于您想使用openas your,$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.

This will work for that:

这将适用于:

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

回答by kenglxn

The following works for me:

以下对我有用:

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

Using Mac OSX 10.7.4 and Sublime Text 2 Build 2181

使用 Mac OSX 10.7.4 和 Sublime Text 2 Build 2181

Note:

笔记:

I have subl as an alias:

我有 subl 作为别名:

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

回答by 2540625

For what it's worth, here's how I solved it:

对于它的价值,这是我解决它的方法:

1) Run in Terminal:

1)在终端运行:

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

This adds a sublalias to /usr/local/bin/pointing to Sublime Text 3 app's binary file. Now running sublin Terminal will launch Sublime Text 3 app.

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

2) Run in Terminal:

2)在终端运行:

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

This adds editor = subl -n -wto the [core]section of the ~/.gitconfigfile. Now running git commitin Terminal will launch Sublime Text 3 app (subl) in a new window (-n), and the command line will wait (-w) until the commit message is saved.

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

Official Sublime Text 3 doc: http://www.sublimetext.com/docs/3/osx_command_line.html

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

回答by Anmol Saraf

To get this working for win7, open the .gitconfig file in c:/users/username/ folder and add the following line with --wait option outside the double quotes.

要使其适用于 win7,请打开 c:/users/username/ 文件夹中的 .gitconfig 文件,并在双引号外添加以下带有 --wait 选项的行。

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

Hope its helpful to win7 users

希望对win7用户有所帮助