修复 msysGit Portable $HOME 位置 [英] Fix msysGit Portable $HOME location
问题描述
我已经在我的闪存驱动器上成功安装和配置了 msysGit Portable,并用它来拉和推送 GitHub 存储库.但是,我似乎总是不得不对 SSH 支持进行混搭.
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.
具体来说,为了让 SSH 找到我的密钥文件,我必须遵循 这些说明 启动 ssh-agent
的第二个实例,然后 ssh- 每次运行 git-bash.bat 时添加
我的密钥.
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.
使用 ssh -v git@github.com
的输出进行调试,我看到 msysGit 默认在我的 Windows 用户目录中查找密钥.它不能那样做;我需要它在便携式驱动器上自己的目录中查找.
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.
如何强制 $HOME 成为程序自己的文件夹?
How can I force $HOME to be the program's own folder?
来自此页面的说明与现在类似-我最初发布的链接已损坏.引用如下.还有这里的 原始 Vox 文章的网络存档.
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.
那么您的会话没有在 ssh-agent 下运行.您可以通过运行以下命令重新启动代理下的新 shell 来解决此问题:
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
您可以在其中用您选择的 shell 替换 bash.完成此操作后,您应该能够运行 ssh-add 以加载该 shell 的密钥.
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.
推荐答案
用于启动git bash的命令是:
The command used to launch git bash is:
C:WindowsSysWOW64cmd.exe /c ""C:ProgGit1.7.1insh.exe" --login -i"
我刚刚在 DOS 会话中尝试了以下操作:
I just tried the following in a DOS session:
C:>C:WindowsSysWOW64cmd.exe /c ""C:ProgGit1.7.1insh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/c/Users/VonC
默认为 $HOME$%HOMEPATH%,但如果我强制使用 %HOME%:
By default, $HOME$%HOMEPATH%, but if I force %HOME%:
set HOME=/another/path
然后启动相同的 bash 会话:
and then launch the same bash session:
C:>C:WindowsSysWOW64cmd.exe /c ""C:ProgGit1.7.1insh.exe" --login -i"
VonC@XXX /c/
$ echo $HOME
/another/path
因此,如果您通过将 HOME 设置为:
So if you wrap the bash call by a script setting the HOME to:
%~dp0
: 你的 U 盘上的封装路径- 或
%~d1yourpath
:%~d1
是驱动器号(如果你的包装器在它上面,则是你的 USB 密钥)
%~dp0
: the path of the wrapper on your USB key- or
%~d1yourpath
: with%~d1
being the drive letter (of your usb key if your wrapper is on it)
,您应该能够将 HOME 强制设为您需要的任何值.
, you should be able to force HOME to whatever value you need.
注意(2011 年 11 月):从那时起,OP dgw 编写了他的 自己的包装器:
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
文章Windows 的便携式 Git:设置 $HOME
环境变量以允许完全的可移植性(包括 SSL 密钥和用于 GitHub 的配置)"还要添加有用的信息.
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.
但是,如果您在便携式驱动器上安装 Git,您会希望您的设置随安装一起移动 - 如果它在其他计算机上可能不存在的文件夹中查找它们,显然他们不会这样做.
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.
所以,我们需要做的是告诉 Portable Git 将其自己文件夹中的特定位置视为主文件夹;这样我们就可以将整个 Git 文件夹复制到我们喜欢的任何地方,并且设置将随它一起移动.
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 Portable $HOME 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!