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


当前回答

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

其他回答

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

步骤2。右键单击文件,选择“编辑”

步骤3。复制粘贴下面的代码,保存并关闭文件

步骤4。双击该文件执行该文件

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

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.\""

这是你的结果:

最简单的方法是从这里安装最新的Git。在安装时,确保启用了Windows资源管理器集成选项。

一旦你完成了,你将得到这些选项,只要你右键单击任何文件夹。

希望能有所帮助。

我在一台新的Windows 10 Pro公司笔记本电脑上安装git -2.38.1-64位时遇到了这个问题。

我尝试了几种方法……并考虑了一个regedit脚本(道德上相当于“护士-电锯!”)…但是通过简单地卸载和重新安装Git(作为“Admin”)解决了这个问题。

具体地说:

Control Panel > Programs/Features > Uninstall Git Reboot Windows Reinstall Git-2.38.1-64-bit as "Admin" Carefull check all the options, especially: "Windows Explorer Integration: Git Bash Here, Git GUI Here <= These are checked by default ... and I'm sure they were both "Y" on the initial install I copied my .gitconfig ("C:\Users\USERNAME.gitconfig") from another PC <= I don't believe this was "essential" ...but I thought I'd mention it... Browse to a local Git repo and verify the Git context menus work <= Success after reinstall!

另一种选择,但使用PowerShell脚本。

这基本上是一个PowerShell脚本,它几乎与这个答案相同(它也添加了图标)。

创建文件(addOpenGitBashHereContextMenu.ps1),粘贴下面的代码,并从PowerShell运行它。

您可能需要更改exePath以指向您的git可执行文件。 也改变contextMenuText如果你想改变上下文菜单中的文本。

$exePath = $env:USERPROFILE + '\scoop\apps\git\current\git-bash.exe'
$contextMenuText = 'Open Git Bash Here'
$regEntryName = 'git_shell'

$regPathShell = 'HKCU:\SOFTWARE\Classes\Directory\Background\shell'
$regPathContextMenu = $regPathShell + '\' + $regEntryName
$regPathCommand = $regPathContextMenu + '\command'
$user = $env:UserName

echo "Setting '$contextMenuText' context menu..."
echo "  User name: '$user'"
echo "  Register path: '$regPathCommand'"
echo "  Executable path: '$exePath'"

# Key: shell
If (-NOT (Test-Path $regPathShell)) {
   New-Item -Path $regPathShell
}

# Key: regEntryName
If (-NOT (Test-Path $regPathContextMenu)) {
   New-Item -Path $regPathContextMenu -Value $contextMenuText

   # Add Icon to context menu
   Set-ItemProperty -Path $regPathContextMenu -Name 'Icon' -Value $exePath
}

# Key: command
If (-NOT (Test-Path $regPathCommand)) {
   New-Item -Path $regPathCommand -Value $exePath
}

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

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

我通过下载并重新安装Git来解决这个问题。 注意:“安装Git for Windows时,默认情况下上下文菜单选项不是‘开启’的。你必须在安装过程中选择它们。”——@nbushnell (我这样做了)