无法修改 git bash Windows 快捷方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2621281/
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
Unable to modify git bash Windows shortcut
提问by netgirlk
Under Windows 7 I'd like to change the settings for the Git Bash Here shell extension command window, e.g. width, height and font. But when I do this, I get an error "Unable to modify the shortcut".
在 Windows 7 下,我想更改 Git Bash Here shell 扩展命令窗口的设置,例如宽度、高度和字体。但是当我这样做时,我收到一个错误“无法修改快捷方式”。
I can modify the shortcut for Git Bash in the Start menu by using "Run as administrator..." This works, but only for Bash windows opened from the Start menu. It doesn'twork for the "Git Bash Here" shell extension and there's no "Run as administrator..." option on right-click context menu.
我可以通过使用“以管理员身份运行...”在“开始”菜单中修改 Git Bash 的快捷方式这有效,但仅适用于从“开始”菜单打开的 Bash 窗口。它不适用于“Git Bash Here”外壳扩展,并且右键单击上下文菜单上没有“以管理员身份运行...”选项。
How do you do it?
你怎么做呢?
回答by sclarson
If you run git bash as administrator by right clicking on its icon and selecting "Run As Administrator" you will be able to change your settings and have them persist.
如果您通过右键单击其图标并选择“以管理员身份运行”以管理员身份运行 git bash,您将能够更改您的设置并使它们保持不变。
You can verify this by closing the admin session then reopening as a normal user.
您可以通过关闭管理会话然后以普通用户身份重新打开来验证这一点。
I did this to set the defaults then just used git as a normal user from then on.
我这样做是为了设置默认值,然后从那时起就将 git 用作普通用户。
Edit: My answer is outdated if you're using the most recent msysgit versionand sebastien.b posted the updated solution with - https://stackoverflow.com/a/7216120/104783
编辑:如果您使用的是最新的 msysgit 版本并且sebastien.b发布了更新的解决方案,我的回答已经过时了 -https://stackoverflow.com/a/7216120/104783
It states
它指出
The fix is to edit the
Git Bash.vbs
script and have it execute the link again, instead of sh.exe. Look for this line:Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
and replace it with this line:
Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")
修复方法是编辑
Git Bash.vbs
脚本并让它再次执行链接,而不是 sh.exe。寻找这一行:Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
并用这一行替换它:
Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")
andrej351 also has a good reminder
andrej351也有很好的提醒
Also, don't forget to select "Defaults" instead of "Properties" from the drop down menu in order to have the settings persisted
另外,不要忘记从下拉菜单中选择“默认值”而不是“属性”,以便保留设置
回答by sebastien.b
Unfortunately, the accepted answer offered by users sparksor bentaylorukdoesn't work anymore (as of git 1.7.6 at least). The Git Bash.vbs
script triggered by "Git Bash Here" doesn't execute the Git Bash
shortcut any longer. It creates a temporary shortcut (.lnk) that executes the bin/sh.exe
executable in the Git install dir instead. Modifying the properties (fonts, color) of either that executable (sh.exe) or the Git Bash shortcut won't help.
不幸的是,用户提供的公认答案sparks或betayloruk不再起作用(至少从 git 1.7.6 开始)。Git Bash.vbs
“ Git Bash Here”触发的脚本Git Bash
不再执行快捷方式。它会创建一个临时快捷方式 (.lnk),bin/sh.exe
用于在 Git 安装目录中执行可执行文件。修改该可执行文件 (sh.exe) 或 Git Bash 快捷方式的属性(字体、颜色)都无济于事。
The fix is to edit the Git Bash.vbs
script and have it execute the link again, instead of sh.exe. Look for this line:
修复方法是编辑Git Bash.vbs
脚本并让它再次执行链接,而不是 sh.exe。寻找这一行:
Dim bash : bash = fso.BuildPath(gitdir, "bin\sh.exe")
and replace it with this line:
并用这一行替换它:
Dim bash : bash = fso.BuildPath(gitdir, "Git Bash.lnk")
回答by bentayloruk
Update: According to some comments and other answers, this answer is only relevant to older versions. Perhaps those prior to 1.7.6.
更新:根据一些评论和其他答案,此答案仅与旧版本相关。也许是 1.7.6 之前的那些。
Full Instructions
完整说明
You can modify the settings applied when using the Git Bash Herecontext menu by doing the following:
您可以通过执行以下操作来修改使用Git Bash Here上下文菜单时应用的设置:
- Open the Git for Windows installation folder. e.g.
C:\Program Files (x86)\Git
. - Right click on the Git Bashshortcut file and select Run As Administrator.
- Click Yesif asked whether you want to give the Windows Command Processor permissions to modify the computer (otherwise your changes will not be persisted).
- Modify the properties as you wish(right click title bar and click properties) and then close the window.
- 打开 Git for Windows 安装文件夹。例如
C:\Program Files (x86)\Git
。 - 右键单击Git Bash快捷方式文件并选择Run As Administrator。
- 如果询问您是否要授予 Windows 命令处理器修改计算机的权限(否则您的更改将不会保留),请单击是。
- 根据需要修改属性(右键单击标题栏并单击属性),然后关闭窗口。
Further Details
更多细节
This works because clicking the Git Bash Hereshell extension menu item runs the command wscript "C:\Program Files (x86)\Git\Git Bash.vbs" "%1"
. This is specified in the registry key HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
. This vbs file sets the current directory and then executes the Git Bashshortcut. Once you have changed the settings on this shortcut, they will always be used when this shortcut is run (regardless of being admin or not).
这是有效的,因为单击Git Bash Hereshell 扩展菜单项运行命令wscript "C:\Program Files (x86)\Git\Git Bash.vbs" "%1"
。这是在注册表项中指定的HKEY_CLASSES_ROOT\Directory\shell\git_shell\command
。这个 vbs 文件设置当前目录,然后执行Git Bash快捷方式。更改此快捷方式的设置后,运行此快捷方式时将始终使用它们(无论是否为管理员)。
回答by Ian Rashkin
In case anyone comes here, as I did, looking for a way to have the Git Bash context menu run as admin (for any reason), thanks to the above, and here are the modified steps I needed to take to make this work:
如果有人来这里,就像我一样,正在寻找一种方法让 Git Bash 上下文菜单以管理员身份运行(出于任何原因),感谢上述内容,以下是我需要采取的修改步骤来完成这项工作:
- in Git directory (e.g. C:\Program Files (x86)\Git) create a shortcut called "Git Bash" with the target '"C:\Program Files (x86)\Git\bin\sh.exe" --login -i'
- Edit Git Bash.vbs as mentioned above, setting the target to "Git Bash.lnk"
- Remove the line 'link.Arguments = "--login -i"' from Git Bash.vbs
- 在 Git 目录(例如 C:\Program Files (x86)\Git)中创建一个名为“Git Bash”的快捷方式,目标是“C:\Program Files (x86)\Git\bin\sh.exe” --login -一世'
- 如上所述编辑 Git Bash.vbs,将目标设置为“Git Bash.lnk”
- 从 Git Bash.vbs 中删除行 'link.Arguments = "--login -i"'
Thanks to all above for pushing me in the right direction.
感谢以上所有推动我朝着正确方向前进的人。
PS, this is with Git-1.9.0-preview20140217 on Windows 7
PS,这是 Windows 7 上的 Git-1.9.0-preview20140217
回答by felippe
I had a similar problem with Git 2.8.2 (64 bit), which resulted in a .exe icon for the Git Bash (this might happen to Shell as well). Here's what I did:
我在 Git 2.8.2(64 位)上遇到了类似的问题,这导致 Git Bash 出现了一个 .exe 图标(这也可能发生在 Shell 上)。这是我所做的:
- Open Git Bash
- Right-click on the opened taskbar icon
- Right-click on Git Bash
- Properties
- Check the Targetand Start infields if they are correct. Mine was targeting to Program Files (x86), but my Git is installed in Program Files
- Save and re-open the Git Bash.
- 打开 Git Bash
- 右键单击打开的任务栏图标
- 右键单击 Git Bash
- 特性
- 检查“目标”和“开始”字段是否正确。我的目标是Program Files (x86),但我的 Git 安装在Program Files 中
- 保存并重新打开 Git Bash。
Why this happened?
为什么会这样?
It was because I already had Git on my Windows, which was a 32 bitsversion, and then I - without knowing about the incompatibility - updated my Git to a newer version running in 64 bits.
这是因为我的 Windows 上已经安装了 Git,它是32 位版本,然后我 - 在不知道不兼容的情况下 - 将我的 Git 更新为运行在64 位的较新版本。
Another way to resolve this would be by totally reinstalling it.
解决此问题的另一种方法是完全重新安装它。
回答by ewall
You can edit the shell's context menu handlers directly in the Windows Registry. The one you're looking for is probably under one of these branches:
您可以直接在 Windows 注册表中编辑外壳的上下文菜单处理程序。您正在寻找的可能位于以下分支之一下:
- HKCR\Directory\Shell\
- HKCR\Directory\ShellEx\ContextMenuHandlers\
- HKCR\Folder\Shell\
- HKCR\Folder\ShellEx\ContextMenuHandlers\
- HKCR\AllFilesystemObjects\shell\
- HKCR\AllFilesystemObjects\shellex\ContextMenuHandlers\
- HKCR\目录\外壳\
- HKCR\Directory\ShellEx\ContextMenuHandlers\
- HKCR\文件夹\外壳\
- HKCR\Folder\ShellEx\ContextMenuHandlers\
- HKCR\AllFilesystemObjects\shell\
- HKCR\AllFilesystemObjects\shellex\ContextMenuHandlers\
Here is a lengthy articleexplaining what you can do there. See the second half of this articlefor more tips on where to look.
回答by leegeorg07
try going to C:\Program Files (x86)\Git or wherever you installed git and edit the git bash shortcut, the size is in the layout tab
尝试转到 C:\Program Files (x86)\Git 或您安装 git 的任何地方并编辑 git bash 快捷方式,大小在布局选项卡中
回答by VonC
You could try freewares like Default Programs Editoror Context Menu Editor, and see if that allows you:
您可以尝试使用Default Programs Editor或Context Menu Editor等免费软件,看看是否允许您:
- to edit properly the shortcut,
- or to define a new shortcut (which behaves like you want) and register that shortcut in the contextual menu.
- 正确编辑快捷方式,
- 或定义一个新的快捷方式(其行为与您想要的一样)并在上下文菜单中注册该快捷方式。
回答by Jimmy Bosse
Check out a modified "Git Bash.vbs" that uses the new method for UNC paths but the old method for local paths.
查看修改后的“Git Bash.vbs”,它对 UNC 路径使用新方法,但对本地路径使用旧方法。
http://groups.google.com/group/msysgit/browse_thread/thread/0603d9565a988d48?pli=1
http://groups.google.com/group/msysgit/browse_thread/thread/0603d9565a988d48?pli=1
The problem I was having with Sebastien's solutions was that the bash path was always the parent of the folder I selected, which I found annoying.
我在 Sebastien 的解决方案中遇到的问题是 bash 路径始终是我选择的文件夹的父级,我觉得这很烦人。
回答by Vitamin C
This solution helped me to change font size:
此解决方案帮助我更改字体大小:
Replace Target of Git Bash link with the following:
%ComSpec% /c "C:\Program Files (x86)\Git\bin\sh.exe" --login -i
Locate Git Bash link on the start menu, right-click and Run as Administrator.
Modify Properties of the opened console, not Defaults. Set whatever font you like. I prefer Consolas 28 since I'm pretty blind :)
You are done. You can close the console and run it again as regular user; the font size should be of your choice.
将 Git Bash 链接的目标替换为以下内容:
%ComSpec% /c "C:\Program Files (x86)\Git\bin\sh.exe" --login -i
在开始菜单上找到 Git Bash 链接,右键单击并以管理员身份运行。
修改打开的控制台的属性,而不是默认值。设置任何你喜欢的字体。我更喜欢 Consolas 28,因为我很盲目:)
你完成了。您可以关闭控制台并以普通用户身份再次运行它;字体大小应该由您选择。