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

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

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

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

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


当前回答

我需要做以下两件事来让Git在Windows中启动notepad++:

将以下内容添加到.gitconfig中: editor = 'C:/Program Files/ notepad++ /notepad++.exe' -multiInst -notabbar -nosession -noPlugin .exe 修改快捷方式以管理员身份启动Git Bash shell,然后使用该快捷方式启动Git Bash shell。我猜上下文菜单项“Git Bash here”没有启动notepad++所需的权限。

在做了以上两件事之后,它起作用了。

其他回答

记事本!

我很喜欢使用Vim,但由于我试图向公司介绍Git,所以我想要一些我们都拥有的东西,并且发现写字板似乎可以正常工作(即Git会等待您完成编辑并关闭窗口)。

git config core.editor '"C:\Program Files\Windows NT\Accessories\wordpad.exe"'

这是在msysgit上使用Git Bash;我没有尝试从Windows命令提示符(如果这有任何不同)。

我很难让Git与写字板、科莫多编辑器以及我给它的几乎所有其他编辑器合作。大多数打开以供编辑,但Git显然不会等待保存/关闭发生。

作为拐杖,我一直在做。

git commit -m "Fixed the LoadAll method"

让事情继续发展。它往往会使我的提交消息比应该的要短一些,但显然在Windows版本的Git上还有一些工作要做。

GitGUI也不是那么糟糕。它需要一点定位,但在那之后,它工作得很好。

假设你想配置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

我的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工具中遇到问题,可以尝试一下。

那些在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文档。