我正在尝试 Windows 上的 Git。我到了尝试“git commit”的地步,但我收到了这个错误:
Terminal is dumb but no VISUAL nor EDITOR defined. Please supply the message using either -m or -F option.
所以我发现我需要一个名为 EDITOR 的环境变量。没问题。我将它设置为指向记事本。这几乎奏效了。默认提交消息在记事本中打开。但是记事本不支持纯换行。我出去了Notepad++ ,但我无法弄清楚如何将 Notepad++ 设置为 %EDITOR%,以便它按预期与 Git 一起工作。
我没有和 Notepad++ 结婚。在这一点上,我不介意我使用什么编辑器。我只是希望能够在编辑器中键入提交消息,而不是命令行(使用-m)。
那些在 Windows 上使用 Git 的人:您使用什么工具来编辑您的提交消息,您必须做什么才能让它工作?
最佳答案
2015 年 9 月更新(6 年后)
last release of git-for-Windows (2.5.3)现在包括:
By configuring
git config core.editor notepad, users can now usenotepad.exeas their default editor.
Configuringgit config format.commitMessageColumns 72will be picked up by the notepad wrapper and line-wrap the commit message after the user edits it.
参见 commit 69b301b通过 Johannes Schindelin (dscho) .
而 Git 2.16 (Q1 2018) 会在生成编辑器时显示一条消息,告诉用户它正在等待用户完成编辑,以防编辑器 打开一个 stash 的窗口或某处不起眼的地方,用户得到 迷路了。
参见 commit abfb04d (2017 年 12 月 7 日),和 commit a64f213 (2017 年 11 月 29 日)Lars Schneider (larsxschneider) .
帮助:Junio C Hamano (gitster) .
(由 Junio C Hamano -- gitster -- merge 于 commit 0c69a13 ,2017 年 12 月 19 日)
launch_editor(): indicate that Git waits for user inputWhen a graphical
GIT_EDITORis spawned by a Git command that opens and waits for user input (e.g. "git rebase -i"), then the editor window might be obscured by other windows.
The user might be left staring at the original Git terminal window without even realizing that s/he needs to interact with another window before Git can proceed. To this user Git appears hanging.Print a message that Git is waiting for editor input in the original terminal and get rid of it when the editor returns, if the terminal supports erasing the last line
原始答案
我刚刚用 git 版本 1.6.2.msysgit.0.186.gf7512 和 Notepad++5.3.1 测试了它
我希望不必必须设置一个 EDITOR 变量,所以我尝试了:
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\""
# or
git config --global core.editor "\"c:\Program Files\Notepad++\notepad++.exe\" %*"
总是给出:
C:\prog\git>git config --global --edit
"c:\Program Files\Notepad++\notepad++.exe" %*: c:\Program Files\Notepad++\notepad++.exe: command not found
error: There was a problem with the editor '"c:\Program Files\Notepad++\notepad++.exe" %*'.
如果我定义一个 npp.bat 包括:
"c:\Program Files\Notepad++\notepad++.exe" %*
然后我输入:
C:\prog\git>git config --global core.editor C:\prog\git\npp.bat
它只适用于 DOS session ,但不适用于 git shell。
(不是说有了 core.editor 配置机制,里面有 "start/WAIT..."的脚本不会工作,只会打开一个新的 DOS 窗口)
Bennett's answer提到避免添加脚本的可能性,而是直接引用程序本身 在简单引号之间。注意斜线的方向!使用 / NOT \ 来分隔路径名中的文件夹!
git config --global core.editor \
"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
或者,如果您使用的是 64 位系统:
git config --global core.editor \
"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin"
但我更喜欢使用脚本(见下文):这样我就可以使用不同的路径或不同的选项,而无需再次注册 git config。
实际的解决方案(使用脚本)是要意识到:
你在配置文件中提到的实际上是一个shell(/bin/sh)脚本,而不是DOS脚本。
那么起作用的是:
C:\prog\git>git config --global core.editor C:/prog/git/npp.bat
用 C:/prog/git/npp.bat:
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst "$*"
或
#!/bin/sh
"c:/Program Files/Notepad++/notepad++.exe" -multiInst -notabbar -nosession -noPlugin "$*"
使用该设置,我可以从 DOS 或 Git Shell 执行“git config --global --edit”,或者我可以执行“git rebase -i ...' 来自 DOS 或 Git Shell。
机器人命令将触发一个新的 notepad++ 实例(因此有 -multiInst' 选项),并等待该实例关闭后再继续。
请注意,我只使用'/',而不是\'。而我installed msysgit using option 2. (将git\bin目录添加到PATH环境变量中,但不要覆盖一些内置的windows工具)
notepad++ 包装器名为 .bat 的事实并不重要。
最好将其命名为“npp.sh”并将其放在 [git]\cmd 目录中(或在您的 PATH 环境变量引用的任何目录中)。
另见:
lightfire228添加 in the comments :
For anyone having an issue where N++ just opens a blank file, and git doesn't take your commit message, see "Aborting commit due to empty message": change your
.bator.shfile to say:
"<path-to-n++" .git/COMMIT_EDITMSG -<arguments>.
That will tell notepad++ to open the temp commit file, rather than a blank new one.
关于windows - 如何设置编辑器以在 Windows 上使用 Git?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10564/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
给定这段代码defcreate@upgrades=User.update_all(["role=?","upgraded"],:id=>params[:upgrade])redirect_toadmin_upgrades_path,:notice=>"Successfullyupgradeduser."end我如何在该操作中实际验证它们是否已保存或未重定向到适当的页面和消息? 最佳答案 在Rails3中,update_all不返回任何有意义的信息,除了已更新的记录数(这可能取决于您的DBMS是否返回该信息)。http://ar.ru