如何向 Windows 资源管理器添加“在此处打开 git-bash...”上下文菜单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24386657/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:14:20  来源:igfitidea点击:

How to add a "open git-bash here..." context menu to the windows explorer?

gitcontextmenuwindows-explorer

提问by sergej

How to add a context (aka right click) menu to the windows explorer that, when clicked, opens the git-bash console in the current explorer folder?

如何将上下文(又名右键单击)菜单添加到 Windows 资源管理器,单击该菜单会在当前资源管理器文件夹中打开 git-bash 控制台?

回答by Ozesh

Step 1. On your desktop right click "New"->"Text Document" with name OpenGitBash.reg

步骤 1. 在您的桌面上右键单击名为 OpenGitBash.reg 的“新建”->“文本文档”

Step 2. Right click the file and choose "Edit"

步骤 2. 右键单击​​文件并选择“编辑”

Step 3. Copy-paste the code below, save and close the file

步骤 3. 复制粘贴以下代码,保存并关闭文件

Step 4. Execute the file by double clicking it

步骤 4. 双击文件执行

Note: You need administrator permission to write to the registry.

注意:您需要管理员权限才能写入注册表。

Windows Registry Editor Version 5.00
; Open files
; Default Git-Bash Location C:\Program Files\Git\git-bash.exe

[HKEY_CLASSES_ROOT\*\shell\Open Git Bash]
@="Open Git Bash"
"Icon"="C:\Program Files\Git\git-bash.exe"

[HKEY_CLASSES_ROOT\*\shell\Open Git Bash\command]
@="\"C:\Program Files\Git\git-bash.exe\" \"--cd=%1\""

; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear

[HKEY_CLASSES_ROOT\Directory\shell\bash]
@="Open Git Bash"
"Icon"="C:\Program Files\Git\git-bash.exe"


[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
@="\"C:\Program Files\Git\git-bash.exe\" \"--cd=%1\""

; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear

[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]
@="Open Git Bash"
"Icon"="C:\Program Files\Git\git-bash.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
@="\"C:\Program Files\Git\git-bash.exe\" \"--cd=%v.\""

And here is your result :

这是你的结果:

enter image description here

在此处输入图片说明

回答by Shaswat Rungta

I had a similar issue and I did this.

我有一个类似的问题,我这样做了。

Step 1 :Type "regedit" in start menu

第一步:在开始菜单中输入“regedit”

Step 2 :Run the registry editor

第 2 步:运行注册表编辑器

Step 3 :Navigate to HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell

第 3 步:导航至HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\Background\shell

Step 4 :Right-click on "shell" and choose New > Key. name the Key "Bash"

第 4 步:右键单击“shell”并选择“新建”>“密钥”。将密钥命名为“Bash”

Right click on "shell" and choose New >Key. name the Key "Bash"

右键单击“shell”并选择“新建”>“键”。 将密钥命名为“Bash”

Step 5 :Modify the value and set it to "open in Bash" This is the text that appears in the right click.

第五步:修改值,设置为“在Bash中打开”这是右键出现的文字。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Step 6 :Create a new key under Bash and name it "command". Set the value of this key to your git-bash.exe path.

第 6 步:在 Bash 下创建一个新密钥并将其命名为“command”。将此键的值设置为您的 git-bash.exe 路径。

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Close the registry editor.

关闭注册表编辑器。

You should now be able to see the option in right click menu in explorer

您现在应该能够在资源管理器的右键菜单中看到该选项

PSGit Bash by default picks up the current directory.

PSGit Bash 默认选择当前目录。

EDIT: If you want a one click approach, check Ozesh's solution below

编辑:如果您想要一键式方法,请查看下面的Ozesh解决方案

回答by Sibeesh Venu

The easiest way is to install the latest Git from here. And while installing, make sure you are enabling the option Windows Explorer Integration.

最简单的方法是从这里安装最新的 Git 。安装时,请确保启用选项Windows Explorer Integration

enter image description here

在此处输入图片说明

Once you are done, you will get those options in whenever you right click on any folder.

完成后,只要右键单击任何文件夹,您就会看到这些选项。

enter image description here

在此处输入图片说明

Hope it helps.

希望能帮助到你。

回答by rasx

Here are the Registry exports (*.regfiles) for Git GUI and Git Bash directly from the Windows installer—Git GUI:

以下是*.reg直接从Windows 安装程序 —Git GUI 中 Git GUI 和 Git Bash的注册表导出(文件):

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui]
@="Git &GUI Here"
"Icon"="C:\Program Files\Git\cmd\git-gui.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_gui\command]
@="\"C:\Program Files\Git\cmd\git-gui.exe\" \"--working-dir\" \"%v.\""

Git bash:

git bash:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell]
@="Git Ba&sh Here"
"Icon"="C:\Program Files\Git\git-bash.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\git_shell\command]
@="\"C:\Program Files\Git\git-bash.exe\" \"--cd=%v.\""

For detail about *.regfiles, see “How to add, modify, or delete registry subkeys and values by using a .reg file” from Microsoft.

有关*.reg文件的详细信息,请参阅Microsoft 的“如何使用 .reg 文件添加、修改或删除注册表子项和值”。

回答by E T

What worked for me was almost this, but with the following REGEDIT path:
HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Directory/background/shelland here I created the key Bash, with the value of what I want the display name to be, and then created another key under this named command with the value as the path to git-bash.exe

对我有用的几乎就是这样,但是使用以下 REGEDIT 路径:
HKEY_LOCAL_MACHINE/SOFTWARE/Classes/Directory/background/shell在这里我创建了密钥 Bash,其值为我想要的显示名称,然后在此命名命令下创建了另一个密钥,其值为git-bash.exe 的路径

I'm on Windows 10 and have a fresh git install that didn't add this automatically for some reason (git version 2.12.0 64bit)

我在 Windows 10 上有一个新的 git 安装,由于某种原因没有自动添加它(git 版本 2.12.0 64 位)

回答by Alexander Kludt

You can install git for windows or Github for windows , both give you the choice while installing to add this feature to your windows explorer. You can find it here:

您可以安装 git for windows 或 Github for windows ,两者都可以让您在安装时选择将此功能添加到您的 Windows 资源管理器中。你可以在这里找到它:

Github for Windows

Windows 版 Github

https://windows.github.com/

https://windows.github.com/

Git for Windows

适用于 Windows 的 Git

http://git-scm.com/

http://git-scm.com/

回答by Marian07

As, @Shaswat Rungta said: "I think the question is more about how to add it after the installation is over."

正如,@Shaswat Rungta 说:“我认为问题更多是关于在安装结束后如何添加它。”

On my PC(Windows 7) I think that the command "Git Bash here" disappeard after I installed Visual Studio 2017.

在我的 PC(Windows 7)上,我认为安装 Visual Studio 2017 后命令“Git Bash here”消失了。

I fixt this by downloadingand installing Git again.

我通过再次下载并安装 Git 解决了这个问题。



NOTE:注意:“在为 Windows 安装 Git 时,上下文菜单选项默认不是“打开”的。您必须在安装过程中选择它们。” – @nbushnell(I did this我这样做了

回答by Jeffy Jahfar

Had a similar issue in adding "Start Command Prompt with Ruby" to context menu as it involves passing parameters along with the patch of cmd. Followed a similar procedure as the solution above

在将“使用 Ruby 启动命令提示符”添加到上下文菜单时遇到了类似的问题,因为它涉及将参数与 cmd 补丁一起传递。遵循与上述解决方案类似的过程

Windows Registry Editor Version 5.00 

[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby]  
@="Cmd With Ruby"  
"Icon"="C:\Windows\System32\cmd.exe"

[HKEY_CLASSES_ROOT\*\shell\Cmd With Ruby\command]
@="\"C:\Windows\System32\cmd.exe\" \"/E:ON /K
\"C:\Ruby25-x64\bin\setrbvars.cmd\"\" \"--cd=%1\"\""


[HKEY_CLASSES_ROOT\Directory\shell\bash]  
@="Cmd With Ruby"  
"Icon"="C:\Windows\System32\cmd.exe"


[HKEY_CLASSES_ROOT\Directory\shell\bash\command]
@="\"C:\Windows\System32\cmd.exe\" \"/E:ON /K
\"C:\Ruby25-x64\bin\setrbvars.cmd\"\" \"--cd=%1\"\"" 

[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]  
@="Cmd With Ruby"  
"Icon"="C:\Windows\System32\cmd.exe"


[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
@="\"C:\Windows\System32\cmd.exe\" \"/E:ON /K
\"C:\Ruby25-x64\bin\setrbvars.cmd\"\" \"--cd=%v.\"\""

回答by qt-x

Usually git bash herecan be run only on directories so you have to go up a directory and right click on the previous directory then select git bash here(of course on Windows OS).
Note: context menu inside a directory does not have a git bash hereoption.

通常git bash here只能在目录上运行,因此您必须上一个目录并右键单击上一个目录然后选择git bash here(当然在 Windows 操作系统上)。
注意:目录内的上下文菜单没有git bash here选项。

回答by kikicarbonell

You can install TortoiseGitfor Windows and include integration in context menu. I consider it the best tool to work with Git on Windows.

您可以为 Windows安装TortoiseGit并在上下文菜单中包含集成。我认为它是在 Windows 上使用 Git 的最佳工具。