【问题标题】:Need to issue ssh-agent command every time I start git-bash每次启动 git-bash 时都需要发出 ssh-agent 命令
【发布时间】:2018-12-07 20:56:36
【问题描述】:

我使用的是 Windows 7。我的公司有一些存储在我们自己的 git 服务器上。最近我也不得不使用 GitHub,但是自从我访问了 GitHub 上的 repo 后,git-bash 的表现就非常不稳定。

这一切归结为每次我打开 git-bash 时,如果我尝试拉动,我会得到:“错误:无法跨越 git:没有这样的文件或目录。”

我的git版本是2.18.0.windows.1

我发现每次启动 git-bash 时都要手动执行这个命令:

eval $(ssh-agent)

我已尝试使用此处的信息: Start ssh-agent on login

这里: https://help.github.com/articles/working-with-ssh-key-passphrases/#auto-launching-ssh-agent-on-git-for-windows

我的 .profile 包含以下内容:

env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }

agent_load_env

# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi

unset env

但是不……我仍然需要在启动 git -bash 时手动执行该命令。 (上面的代码应该消除这种必要性。)

【问题讨论】:

    标签: windows ssh git-bash


    【解决方案1】:

    这两个链接都建议在.bash_profile.bashrc 中添加(参见“What are the functional differences between .profile .bash_profile and .bashrc”)

    先尝试一下,而不是使用.profile

    确保您的 git bash 将 echo $HOME 设为预期值:set HOME 先到 %USERPROFILE%

    【讨论】:

    • 我将它添加到所有三个 - .profile、.bash_profile 和 .bashrc。没有不同。 echo $HOME 反映了正确的值。
    • @dauber "cannot span git: No such file or directory.": 打开 bash 后,你的 $PATH 中有 git 吗? which git 会返回一些东西吗?
    猜你喜欢
    • 2017-07-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 2022-11-01
    • 1970-01-01
    • 2019-04-27
    • 2015-09-03
    • 1970-01-01
    相关资源
    最近更新 更多