我如何使崇高文本成为Git的默认编辑器?

时间:2023-01-12 22:20:19

I have a problem setting Sublime Text 2 as the core.editor with git.

我有一个问题,把崇高的文字2作为核心。编辑器与git。

I've read through every post I could find addressing the problem, but still nothing is working for me. I am running Windows.

我读过每一篇文章,我能找到解决这个问题的方法,但仍然没有任何东西适合我。我运行Windows。

I have done:

我所做的:

git config --global core.editor "'C:/Program Files/Sublime Text 2/sublime_text.exe'"

and tried that with various arguments like -m. When I open my .gitconfig, this is what is in there:

用-m这样的参数来尝试。当我打开。gitconfig,这就是里面的内容:

[user]
    name = Spencer Moran
    email = smoran02@gmail.com
[core]
    editor = 'C:/Program Files/Sublime Text 2/sublime_text.exe'

If I go to Git and type:

如果我去Git输入:

README.markdown --edit

the README file opens in Notepad, not Sublime Text.

自述文件以记事本打开,而不是崇高的文本。

Does anyone have any idea what I'm doing wrong or how I could fix this?

有人知道我做错了什么吗?

13 个解决方案

#1


309  

Windows

Sublime Text 2 (Build 2181)

The latest Build 2181 just added support for the -w (wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such.

最新的Build 2181只增加了对-w (wait)命令行参数的支持。以下配置将允许ST2作为Windows上的默认git编辑器工作。这将允许git为提交消息等打开ST2。

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

Sublime Text 3 (Build 3065)

Sublime Text 3 (Build 3065) added the subl.exe command line helper. Use subl.exe -h for the options available to you. I have hot_exit: true and remember_open_files: true set in my Sublime Text user settings. I have found the following to git config to work well for me.

崇高的文本3(构建3065)添加了subl。exe命令行助手。使用subl。exe -h为您提供的选项。我有hot_exit: true and remember_open_files: true set在我的优秀文本用户设置中。我发现下面的git config可以很好地为我工作。

git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"

Mac and Linux

Set Sublime as your editor for Git by typing the following command in the terminal:

在终端输入以下命令,将崇高设置为Git的编辑器:

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

git配置——全球核心。编辑“subl - n - w”


With this Git config, the new tab is opened in my editor. I edit my commit message, save the tab (Ctrl+S) and close it (Ctrl+W).

使用这个Git配置,新的选项卡将在我的编辑器中打开。我编辑提交消息,保存选项卡(Ctrl+S)并关闭它(Ctrl+W)。

Git will wait until the tab is closed to continue its work.

Git将等到选项卡关闭后再继续工作。

#2


91  

You can use this command on Mac and Linux:

你可以在Mac和Linux上使用这个命令:

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

#3


9  

For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.

对于Mac OS X文件~/。gitconfig在[core]下,我不得不把这段代码放在我这边来解决这个问题。

editor = /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl  -n -w

This was when subl was working fine but git was unable to access it. And was displaying these errors

这是在subl运行良好的时候,但是git无法访问它。显示这些错误

subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.

#4


6  

what worked for me in cygwin/zsh:

什么在cygwin/zsh对我有效:

in /usr/local/bin create subl_git file

在/usr/local/bin中创建subl_git文件

#!/bin/bash
/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -w -n `cygpath -w $@`

in gitconfig:

在gitconfig:

editor = /usr/local/bin/subl_git

#5


6  

With Sublime Text 2 and the following configuration, if nothing happens when you close the git commit's comment file :

使用崇高的文本2和以下配置,如果在关闭git提交的注释文件时没有发生任何事情的话:

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

If the git commit doesn't finish when you close the COMMIT_EDITMSG comment file in Sublime, I've found this is probably because you are running CMD in administrator mode (and have a Sublime Text already opened in non admin mode). I had the same problem and it worked for me when I started my CMD in normal mode.

如果在您关闭COMMIT_EDITMSG注释文件时,如果git提交没有完成,我发现这可能是因为您在管理员模式下运行CMD(并且在非管理模式下已经打开了一个非常好的文本)。我也遇到了同样的问题,当我在正常模式下启动CMD时,它对我起了作用。

Ps : just wanted to answer to the problem @david pointed out in the accepted answer's comments, but I couldn't post comment since I'm new here... so I've made a new answer, because I think this can be useful to some people encountering the problem.

Ps:我只是想回答@david在回复中指出的问题,但是我不能发表评论,因为我是新来的……所以我有了一个新的答案,因为我认为这对一些遇到问题的人是有用的。

#6


5  

I just successfully made it with the help of PowerShell (command line tools for windows, which is also be use as the default command line on GithubforWindows)

我刚刚在PowerShell (windows的命令行工具,它也是GithubforWindows上的默认命令行)的帮助下成功完成的

Just make a folder "WindowsPowerShell" on "C:\Users\%username%\My Documents". Then, create a file called "profile.ps1". Make sure that you have the correct file extension, .ps1 and not .txt. inside the profile.ps1, put this line to set an alias command:

只需要在“C:\用户\用户名%\我的文档”上创建一个文件夹“WindowsPowerShell”。然后,创建一个名为“profile.ps1”的文件。确保你有正确的文件扩展名。ps1而不是。txt。在概要文件。ps1,将此行设置为别名命令:

Set-Alias subl 'c:\program files\sublime text 2\sublime_text.exe'

Make sure the sublime directory on your machine is correct. You can also see the configuration details in here.

确保机器上的崇高目录是正确的。您还可以在这里看到配置细节。

Now, I can edit files with Sublime Text 2 via PowerShell command just by typing:

现在,我只需输入:

subl filename

Hopefully this is usefull...

希望这是有用的……

#7


5  

For Mac & Sublime Text 3:

Mac & Sublime文本3:

If git config --global core.editor "subl -n -w" doesn't work, use this git config command:

如果git配置——全局核心。编辑器“subl -n -w”不工作,使用这个git配置命令:

$ git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -n -w"

Note: it does not contain escaping backslashes.

注意:它不包含转义反斜杠。

#8


3  

I've faced the same problem with git editor in Windows this evening, and finally I've got it.

今晚我在Windows中遇到了相同的问题,最终我得到了它。

You'll need to set your editor path with the bash syntax and using the DOS 8.3 format to avoid spaces:

您需要使用bash语法设置编辑器路径,并使用DOS 8.3格式来避免空格:

This doesn't work (for me):

这(对我)不起作用:

git config --global core.editor "C://Program files/Sublime Text/sublime_text.exe"

This do:

这个做的事:

git config --global core.editor /C/PROGRA~1/SUBLIME~1/sublime_text.exe

You can get the DOS 8.3 name for a directory with dir /x

您可以使用dir /x获得目录的DOS 8.3名称

#9


2  

If you are Mac User, then here is how:

如果你是Mac用户,以下是如何:

git config --global core.editor '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'

#10


1  

I was just struggling with this for some reason, none of the examples above quite worked for me. This was my solution however:

出于某种原因,我一直在努力解决这个问题,上面的例子没有一个对我很有效。但这是我的解决方案:

 git config --global core.editor "'c:/<path to sublime>/sublime_text.exe' -w $*"

You specifically need the ' ' around the path and the $* at the end of the args, all in " ".

你特别需要路径上的' '和args末尾的$*,都在" "中。

#11


1  

well, i had some trouble invoking notepad++ from gitbash even after setting it as my core.editor.

我在将它设置为core.editor之后,仍然无法从gitbash调用notepad++。

i got it all solved by appending the below line to my .bashrc file in my gitbash installation directory.

我通过在gitbash安装目录中将下面一行添加到my .bashrc文件中得到了所有的解决方案。

alias npp='winpty "C:/Program Files (x86)/Notepad++/notepad++.exe"'

so, i can invoke notepad++ with the alias "npp". i feel this can help you if you change the directory to the respective editor you want to use.

因此,我可以使用别名“npp”调用notepad++ +。如果您将目录更改为您想要使用的编辑器,我觉得这对您有帮助。

#12


1  

For MAC Users I can say for Sublime use the following:

对于MAC用户,我可以这样说:

First Check the .gitconfig file using command:

首先使用命令检查.gitconfig文件:

  1. cd ~
  2. cd ~
  3. ls -la
  4. ls拉
  5. cat .gitconfig
  6. 猫.gitconfig

Now one can add this configuration:

现在可以添加这个配置:

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

Where l1 will tell to start at line 1.

l1从第一行开始。

#13


0  

For Windows 7 I have found the following solution works:

对于Windows 7,我发现以下解决方案是有效的:

git config --global core.editor "C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -n -w"

#1


309  

Windows

Sublime Text 2 (Build 2181)

The latest Build 2181 just added support for the -w (wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such.

最新的Build 2181只增加了对-w (wait)命令行参数的支持。以下配置将允许ST2作为Windows上的默认git编辑器工作。这将允许git为提交消息等打开ST2。

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

Sublime Text 3 (Build 3065)

Sublime Text 3 (Build 3065) added the subl.exe command line helper. Use subl.exe -h for the options available to you. I have hot_exit: true and remember_open_files: true set in my Sublime Text user settings. I have found the following to git config to work well for me.

崇高的文本3(构建3065)添加了subl。exe命令行助手。使用subl。exe -h为您提供的选项。我有hot_exit: true and remember_open_files: true set在我的优秀文本用户设置中。我发现下面的git config可以很好地为我工作。

git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"

Mac and Linux

Set Sublime as your editor for Git by typing the following command in the terminal:

在终端输入以下命令,将崇高设置为Git的编辑器:

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

git配置——全球核心。编辑“subl - n - w”


With this Git config, the new tab is opened in my editor. I edit my commit message, save the tab (Ctrl+S) and close it (Ctrl+W).

使用这个Git配置,新的选项卡将在我的编辑器中打开。我编辑提交消息,保存选项卡(Ctrl+S)并关闭它(Ctrl+W)。

Git will wait until the tab is closed to continue its work.

Git将等到选项卡关闭后再继续工作。

#2


91  

You can use this command on Mac and Linux:

你可以在Mac和Linux上使用这个命令:

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

#3


9  

For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.

对于Mac OS X文件~/。gitconfig在[core]下,我不得不把这段代码放在我这边来解决这个问题。

editor = /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl  -n -w

This was when subl was working fine but git was unable to access it. And was displaying these errors

这是在subl运行良好的时候,但是git无法访问它。显示这些错误

subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.

#4


6  

what worked for me in cygwin/zsh:

什么在cygwin/zsh对我有效:

in /usr/local/bin create subl_git file

在/usr/local/bin中创建subl_git文件

#!/bin/bash
/cygdrive/c/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -w -n `cygpath -w $@`

in gitconfig:

在gitconfig:

editor = /usr/local/bin/subl_git

#5


6  

With Sublime Text 2 and the following configuration, if nothing happens when you close the git commit's comment file :

使用崇高的文本2和以下配置,如果在关闭git提交的注释文件时没有发生任何事情的话:

git config --global core.editor "'c:/program files/sublime text 2/sublime_text.exe' -w"

If the git commit doesn't finish when you close the COMMIT_EDITMSG comment file in Sublime, I've found this is probably because you are running CMD in administrator mode (and have a Sublime Text already opened in non admin mode). I had the same problem and it worked for me when I started my CMD in normal mode.

如果在您关闭COMMIT_EDITMSG注释文件时,如果git提交没有完成,我发现这可能是因为您在管理员模式下运行CMD(并且在非管理模式下已经打开了一个非常好的文本)。我也遇到了同样的问题,当我在正常模式下启动CMD时,它对我起了作用。

Ps : just wanted to answer to the problem @david pointed out in the accepted answer's comments, but I couldn't post comment since I'm new here... so I've made a new answer, because I think this can be useful to some people encountering the problem.

Ps:我只是想回答@david在回复中指出的问题,但是我不能发表评论,因为我是新来的……所以我有了一个新的答案,因为我认为这对一些遇到问题的人是有用的。

#6


5  

I just successfully made it with the help of PowerShell (command line tools for windows, which is also be use as the default command line on GithubforWindows)

我刚刚在PowerShell (windows的命令行工具,它也是GithubforWindows上的默认命令行)的帮助下成功完成的

Just make a folder "WindowsPowerShell" on "C:\Users\%username%\My Documents". Then, create a file called "profile.ps1". Make sure that you have the correct file extension, .ps1 and not .txt. inside the profile.ps1, put this line to set an alias command:

只需要在“C:\用户\用户名%\我的文档”上创建一个文件夹“WindowsPowerShell”。然后,创建一个名为“profile.ps1”的文件。确保你有正确的文件扩展名。ps1而不是。txt。在概要文件。ps1,将此行设置为别名命令:

Set-Alias subl 'c:\program files\sublime text 2\sublime_text.exe'

Make sure the sublime directory on your machine is correct. You can also see the configuration details in here.

确保机器上的崇高目录是正确的。您还可以在这里看到配置细节。

Now, I can edit files with Sublime Text 2 via PowerShell command just by typing:

现在,我只需输入:

subl filename

Hopefully this is usefull...

希望这是有用的……

#7


5  

For Mac & Sublime Text 3:

Mac & Sublime文本3:

If git config --global core.editor "subl -n -w" doesn't work, use this git config command:

如果git配置——全局核心。编辑器“subl -n -w”不工作,使用这个git配置命令:

$ git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -n -w"

Note: it does not contain escaping backslashes.

注意:它不包含转义反斜杠。

#8


3  

I've faced the same problem with git editor in Windows this evening, and finally I've got it.

今晚我在Windows中遇到了相同的问题,最终我得到了它。

You'll need to set your editor path with the bash syntax and using the DOS 8.3 format to avoid spaces:

您需要使用bash语法设置编辑器路径,并使用DOS 8.3格式来避免空格:

This doesn't work (for me):

这(对我)不起作用:

git config --global core.editor "C://Program files/Sublime Text/sublime_text.exe"

This do:

这个做的事:

git config --global core.editor /C/PROGRA~1/SUBLIME~1/sublime_text.exe

You can get the DOS 8.3 name for a directory with dir /x

您可以使用dir /x获得目录的DOS 8.3名称

#9


2  

If you are Mac User, then here is how:

如果你是Mac用户,以下是如何:

git config --global core.editor '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl'

#10


1  

I was just struggling with this for some reason, none of the examples above quite worked for me. This was my solution however:

出于某种原因,我一直在努力解决这个问题,上面的例子没有一个对我很有效。但这是我的解决方案:

 git config --global core.editor "'c:/<path to sublime>/sublime_text.exe' -w $*"

You specifically need the ' ' around the path and the $* at the end of the args, all in " ".

你特别需要路径上的' '和args末尾的$*,都在" "中。

#11


1  

well, i had some trouble invoking notepad++ from gitbash even after setting it as my core.editor.

我在将它设置为core.editor之后,仍然无法从gitbash调用notepad++。

i got it all solved by appending the below line to my .bashrc file in my gitbash installation directory.

我通过在gitbash安装目录中将下面一行添加到my .bashrc文件中得到了所有的解决方案。

alias npp='winpty "C:/Program Files (x86)/Notepad++/notepad++.exe"'

so, i can invoke notepad++ with the alias "npp". i feel this can help you if you change the directory to the respective editor you want to use.

因此,我可以使用别名“npp”调用notepad++ +。如果您将目录更改为您想要使用的编辑器,我觉得这对您有帮助。

#12


1  

For MAC Users I can say for Sublime use the following:

对于MAC用户,我可以这样说:

First Check the .gitconfig file using command:

首先使用命令检查.gitconfig文件:

  1. cd ~
  2. cd ~
  3. ls -la
  4. ls拉
  5. cat .gitconfig
  6. 猫.gitconfig

Now one can add this configuration:

现在可以添加这个配置:

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

Where l1 will tell to start at line 1.

l1从第一行开始。

#13


0  

For Windows 7 I have found the following solution works:

对于Windows 7,我发现以下解决方案是有效的:

git config --global core.editor "C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe -n -w"