我正在试用Windows上的Git。我到了尝试“git commit”的地步,我得到了这个错误:

终端是哑的,但没有视觉也 编辑器定义。请提供 消息使用-m或-F选项。

所以我发现我需要一个叫做EDITOR的环境变量。没有问题。我把它设置为指向记事本。这几乎奏效了。默认的提交消息在记事本中打开。但是记事本不支持换行。我出去得到了notepad++,但我不知道如何将notepad++设置为%EDITOR%,使其与Git正常工作。

我没有嫁给notepad++。在这一点上,我不介意我使用什么编辑器。我只是希望能够在编辑器中而不是在命令行中输入提交消息(使用-m)。

那些在Windows上使用Git的人:你使用什么工具来编辑你的提交消息,你必须做什么才能让它工作?


当前回答

我正在使用GitHub for Windows,这是一个很好的可视化选项。但我也更喜欢命令行,所以当我在Git shell中打开一个存储库时,我只需要设置以下内容:

git config --global core.editor vim

这很有效。

其他回答

假设你想配置VsCode为你的编辑器。 做以下几点:

在.gitconfig文件中添加以下代码行:

gitconfig文件的默认位置是C:\Users\USER_NAME\.gitconfig

[core]
  editor = code -w -n
[diff]
  tool = vscode
[difftool "vscode"]
  cmd = code -w -n --diff $LOCAL $REMOTE
[merge]
  tool = vscode
[mergetool "vscode"]
  cmd = code -w -n $MERGED

注意: -w是必选项,告诉git等待vscode加载。 -n是可选的,它告诉git在新窗口中打开vscode。

如果你想在Windows中配置一个自定义的编辑器路径:

您需要将字code替换为VsCode的“。exe”路径。

例如:

[core]
  editor = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n
[diff]
  tool = vscode
[difftool "vscode"]
  cmd = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n --diff $LOCAL $REMOTE
[merge]
  tool = vscode
[mergetool "vscode"]
  cmd = "'C:/Users/Tal/AppData/Local/Programs/Microsoft VS Code/Code.exe'" -w -n $MERGED

注意: 你需要用单引号包围路径”。 路径中的斜杠应该是正斜杠/。

再举一个例子:

[core]
    editor = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n

[diff]
    tool = vscode
[difftool "vscode"]
    cmd = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n --diff $LOCAL $REMOTE

[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = \"C:\\Users\\Tal\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" -w -n $MERGED

更新:

VsCode现在支持“3路合并”! 更新版本为1.69和1.70.0。 所以现在你可以启用VsCode的“mergetool”来查看3向合并。

为此,你需要更新行:

[mergetool "vscode"]
      cmd = code -w -n $MERGED

与新行:

[mergetool "vscode"]
      cmd = code -w -n --merge $REMOTE $LOCAL $BASE $MERGED

这是我使用Geany作为Git编辑器的设置:

git config --global core.editor C:/path/to/geany.bat

geany.bat中包含以下内容:

#!/bin/sh
"C:\Program Files\Geany\bin\Geany.exe" --new-instance "$*"

它可以在DOS控制台和msysgit中工作。

我更喜欢使用Emacs。设置它可能有点棘手。

下载Emacs并解压到c:\ Emacs这样的地方。 运行c: \ emacs \ bin \ addpm.exe。如果你使用windowsvista或以上版本,你需要右键点击“以管理员身份运行”。这将把可执行文件放到您的路径中。 在.emacs文件中添加(server-start)。关于将. Emacs文件放在哪里,请参阅Emacs Windows FAQ。 Git配置——全局核心。编辑emacsclientw

Git现在将在现有的Emacs进程中打开文件。您必须从c:\emacs\bin\runemacs.exe手动运行现有进程。

那些在Windows上使用Git的人:你使用什么工具来编辑你的提交消息,你必须做什么才能让它工作?

在我的git编辑器和通用代码编辑器中,我发现在Windows和Linux中最有用的工具是Sublime Text 3。它工作得很好,但需要一点设置才能让它正确,所以我在这里完整地记录了这一点:

如何让Git使用我选择的编辑器进行提交?- Sublime Text 3作为Git编辑器的最佳设置(Windows和Linux指令)

关于我的主编辑器的边注:对于大型项目,我使用Eclipse作为我的主编辑器,Sublime Text 3作为我的git编辑器,当我需要使用它的高级功能时,如多光标模式,垂直/列选择模式等。对于中小型项目,我只使用Sublime Text 3本身。有关Eclipse的设置说明,请参阅我的PDF文档。

我的PortableGit 1.6运行良好,但在升级到PortableGit 1.7 Windows版本后,我遇到了一些问题。有些Git命令可以打开notepad++ .exe,但有些不能,尤其是Git rebase的行为不同。

问题是有些命令运行Windows的cmd进程,有些命令使用Unix的cmd进程。我想给启动属性notepad++编辑器,所以我需要有一个自定义脚本。我的解是这个。

Create a script to run an appropriate text editor. The script looks weird, but it handles both the Windows and Unix variation. c:/PortableGit/cmd/git-editor.bat #!/bin/sh # Open a new instance function doUnix() { "c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar $* exit } doUnix $* :WINCALL "c:\program files\notepad++\notepad++.exe" -multiInst -nosession -notabbar %* Set the global core.editor variable The script was saved to git/cmd folder, so it's already in a gitconsole path. This is mandatory as a full path may not work properly. git config --global core.editor "git-editor.bat"

现在我可以运行git commit -a和git rebase -i master命令。如果你在Git Windows工具中遇到问题,可以尝试一下。