修复msysGit便携式$ HOME位置 [英] Fix msysGit Portable $HOME location
问题描述
我已经在我的闪存驱动器上成功安装并配置了msysGit Portable,并用它来拉和推GitHub仓库。然而,我似乎总是不得不嘲笑SSH的支持。
特别是,为了让SSH找到我的密钥文件,我必须遵循这些说明开始第二个实例 ssh-agent
,然后
$ b 使用 ssh -v git@github.com
的输出进行调试,我可以看到msysGit默认为我的Windows用户目录来查找密钥。它不能那样做;我需要它在自己的便携式驱动器上查找它。
如何强制$ HOME成为程序自己的文件夹?
破坏Vox链接的更新
此页面与我最初发布的现在已断开的链接类似。引用如下。这里还有原始Vox文章的webarchive 。
<但是,如果您尝试此操作并获得:
%ssh-add
无法打开与您的连接认证代理。
那么你的会话没有在ssh-agent下运行。您可以通过运行以下代理重新启动新shell:
exec ssh-agent bash
您可以用您选择的shell替换bash。一旦你这样做了,你应该能够运行ssh-add来为你的shell加载你的密钥。
用于启动git bash的命令是:
C:\Windows\SysWOW64\cmd.exe / cC:\Prog\Git\1.7.1\bin\\ \\ sh.exe--login -i
我在DOS会话中尝试了以下操作:
C:\> C:\ Windows \SysWOW64\cmd.exe / cC:\\ \\Prog\Git\1.7.1\bin\sh.exe--login -i
VonC @ XXX / c /
$ echo $ HOME
/ c /用户/ VonC
默认情况下,$ HOME $%HOMEPATH%,但如果强制%HOME%
set HOME = / another / path
,然后启动相同的bash会话:
C:\> C: \Windows\SysWOW64\cmd.exe / cC:\Prog\Git\1.7.1\bin\sh.exe--login -i
VonC @ XXX / c /
$ echo $ HOME
/ another / path
您通过设置HOME的脚本包装bash调用:
%〜dp0
:USB密钥包装的路径
%〜d1 \您的路径
:with <$ c
$ b $ p>,你应该能够强制HOME给你需要的任何值。
注意(2011年11月) , OP dgw 写了他的自己的包装器:
git-bash-portable.bat
:
@echo off
rem Copyright(C):2010 Voyagerfan5761
rem http://technobabbl.es/
set USERPROFILE =%〜dp0
set HOMEDRIVE =%〜d0
set HOMEPATH =%〜p0
set HOME =%〜dp0
set HISTFILE =%USERPROFILE%.bash_history
rem设置BASHRC =%USERPROFILE%.bashrc
git-bash.bat
文章 $ HOME 环境变量以允许完整的可移植性(包括使用SSL密钥和配置)使用GitHub)也添加了有用的信息。
但是,如果您将Git安装在便携式硬盘上,你的设置随着安装而移动 - 显然,如果它在其他计算机上可能不存在的文件夹中查找它们,它们不会。
所以,我们需要做的是告诉便携式Git将自己的文件夹中的特定位置作为主文件夹;这样我们就可以将整个Git文件夹复制到任何我们喜欢的位置,并且设置将随之移动。
I have successfully installed and configured msysGit Portable on my flash drive, and have used it to pull and push GitHub repos. However, I seem to always have to kludge the SSH support.
Specifically, in order for SSH to find my key files, I have to follow these instructions to start a second instance of ssh-agent
and then ssh-add
my key every time I run git-bash.bat.
Using the output of ssh -v git@github.com
to debug I see that msysGit defaults to my Windows user directory to look for keys. It can't do that; I need it to look in its own directory on the portable drive.
How can I force $HOME to be the program's own folder?
Update for broken Vox link
Instructions from this page are similar to the now-broken link I originally posted. Quoted below. Also here's the webarchive of original Vox article.
However, if you try this and get:
% ssh-add Could not open a connection to your authentication agent.
then your session is not running under the ssh-agent. You can get around this by restarting a new shell under the agent by running:
exec ssh-agent bash
where you can replace bash with the shell of your choice. Once you do this, you should be able to run ssh-add to load your key for that shell.
The command used to launch git bash is:
C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"
I just tried the following in a DOS session:
C:\>C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/c/Users/VonC
By default, $HOME$%HOMEPATH%, but if I force %HOME%:
set HOME=/another/path
and then launch the same bash session:
C:\>C:\Windows\SysWOW64\cmd.exe /c ""C:\Prog\Git\1.7.1\bin\sh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/another/path
So if you wrap the bash call by a script setting the HOME to:
%~dp0
: the path of the wrapper on your USB key- or
%~d1\your\path
: with%~d1
being the drive letter (of your usb key if your wrapper is on it)
, you should be able to force HOME to whatever value you need.
Note (November 2011): since then, the OP dgw has written his own wrapper:
git-bash-portable.bat
:
@echo off
rem Copyright (C): 2010 Voyagerfan5761
rem http://technobabbl.es/
set USERPROFILE=%~dp0
set HOMEDRIVE=%~d0
set HOMEPATH=%~p0
set HOME=%~dp0
set HISTFILE=%USERPROFILE%.bash_history
rem set BASHRC=%USERPROFILE%.bashrc
git-bash.bat
The article "Portable Git for Windows: setting the $HOME
environment variable to allow complete portability (including SSL keys and configuration for use with GitHub)" also add useful information.
However, if you install Git on a portable drive, you'll want your settings to travel with the installation—which obviously they won't if it is looking for them in a folder which may not exist on other computers.
So, what we need to do is tell Portable Git to treat a specific location within its own folder as the home folder; that way we can copy the whole Git folder anywhere we like and the settings will travel with it.
这篇关于修复msysGit便携式$ HOME位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!