windows 无法获取 git 扩展以将某些内容推送到 github SSH 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4112781/
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
Cannot get git extensions to push something to github SSH problems
提问by max
Im trying to use git extensions and I really like it so far, but I don't manage to push to github. The following command works fine in git bash:
我正在尝试使用 git 扩展,到目前为止我真的很喜欢它,但我无法推送到 github。以下命令在 git bash 中工作正常:
git push "origin" master:master
and then when I push with git extensions I get this:
然后当我用 git 扩展推送时,我得到了这个:
C:\Program Files\Git\bin\git.exe push "origin" master:master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Done
In the git settings it just has openSSH selected which I would like to keep because putty seems more hassle.
在 git 设置中,它只选择了 openSSH,我想保留它,因为腻子看起来更麻烦。
The remote addres I have added in gitextensions, actually the only thing I have done from the bash just to test is the command above and gerenating the SSH keys. All else is set up in git extensions. So I suppose everything must be set up correctly. Eg, the email adress and name are correct...
我在 gitextensions 中添加的远程地址,实际上我从 bash 所做的唯一一件事就是测试上面的命令并生成 SSH 密钥。所有其他内容都在 git 扩展中设置。所以我想一切都必须正确设置。例如,电子邮件地址和姓名是正确的...
ssh [email protected]
also connects fine, from bash
也连接正常,来自 bash
edit:
编辑:
So I can reproduce the error by putting the command from git-extensions in cmd. Appearantly there is a difference between running from git bash and from cmd and git-extensions runs this command like a windows command... any clues?
所以我可以通过将来自 git-extensions 的命令放入 cmd 来重现错误。显然,从 git bash 和 cmd 运行之间存在差异,并且 git-extensions 像 Windows 命令一样运行此命令......有什么线索吗?
update: If I choose git-bash from the menu in git-extensions I get a window that is exactlythe same as when I right click in explorer on my repo folder and choose git bash here. Now, in the one opened from explorer I can push and in the one opened from extensions I get the public key problem.
更新:如果我从 git-extensions 的菜单中选择 git-bash,我会看到一个窗口,与我在 repo 文件夹中右键单击资源管理器并在此处选择 git bash 时完全相同。现在,在从资源管理器打开的那个我可以推送,在从扩展打开的那个我得到公钥问题。
采纳答案by max
Ok, I solved it.
好的,我解决了。
I opened the git bash from git extensions and a git bash using the explorer shell extensions. I then ran ssh -vvv [email protected] from both to see the difference.
我从 git 扩展中打开了 git bash,并使用资源管理器外壳扩展打开了 git bash。然后我从两者运行 ssh -vvv [email protected] 以查看差异。
It turned out that because I changed the location of the git config file ( I tend to reformat every now and then, so c:\documents and settings... is notoriously bad for storing anything I might want to keep persistent), when run from git extensions git was also looking for the ssh keys in a different location. So I added the .ssh folder where my git cofig file is and now it works fine. I think git-extensions sets the HOME variable for git to whatever you set as path for the config file.
事实证明,因为我更改了 git 配置文件的位置(我倾向于时不时地重新格式化,所以 c:\documents and settings... 对于存储我可能想要保持持久的任何东西是出了名的糟糕),当运行时从 git extensions git 也在寻找不同位置的 ssh 密钥。所以我在我的 git cofig 文件所在的位置添加了 .ssh 文件夹,现在它工作正常。我认为 git-extensions 将 git 的 HOME 变量设置为您为配置文件设置的路径。
Now, that was not obvious...
现在,这并不明显......
回答by max
Things to check for:
需要检查的事项:
- Presence of
HOME
environment variable. - Presence of
%HOME%\.ssh\
and RSA keys there.
- 存在
HOME
环境变量。 - 存在
%HOME%\.ssh\
和 RSA 密钥。
When you run git from command promt it is preferred to run git.cmd
, because it fixes HOME
automatically:
当您从命令 promt 运行 git 时,首选 run git.cmd
,因为它会HOME
自动修复:
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%
To fix gitextensions, define HOME
variable and set it to same value as USERPROFILE
要修复 gitextensions,请定义HOME
变量并将其设置为与USERPROFILE
回答by wolandscat
The correct answer is the one from 'max' (set your HOME env var manually), but it may help some to understand why the problem is happening (as Git gets more users around the world it's going to be very common).
正确答案是来自“max”的答案(手动设置您的 HOME env var),但它可能有助于一些人理解问题发生的原因(随着 Git 在世界各地获得更多用户,这将非常普遍)。
Cygwin sets $HOME to /home/yourname, but that variable is not known in the Windows environment. So if you open a bash window and do env | grep HOME you'll see all three 'HOME' variables mentioned here, and you might wonder why Gitextensions doesn't use your proper cygwin HOME - which is because its .bat file invocation doesn't see it - it only sees what you see from doing 'set' in a windows console.
Cygwin 将 $HOME 设置为 /home/yourname,但该变量在 Windows 环境中未知。因此,如果您打开一个 bash 窗口并执行 env | grep HOME 你会看到这里提到的所有三个“HOME”变量,你可能想知道为什么 Gitextensions 不使用你正确的 cygwin HOME - 这是因为它的 .bat 文件调用没有看到它 - 它只看到你看到的从在 Windows 控制台中执行“设置”。
It's mystifying why it doesn't do this evaluation later and get the proper cygwin path since it knows how to invoke bash, but (at least in versions up to 2.41) you have to do this manual change in the settings or in .gitconfig.
令人困惑的是为什么它稍后不进行此评估并获得正确的 cygwin 路径,因为它知道如何调用 bash,但是(至少在 2.41 之前的版本中)您必须在设置或 .gitconfig 中进行此手动更改。
回答by Smita Hodiggeri
Yes, not setting the HOME varible was the issue for me too.
是的,不设置 HOME 变量对我来说也是一个问题。
Set the HOME variable as %USERPROFILE%
and regenerate the Private and Public keys, then try cloning—it should work now.
将 HOME 变量设置为%USERPROFILE%
并重新生成私钥和公钥,然后尝试克隆——它现在应该可以工作了。
回答by OJ.
When you fire up git bash directly you'll land in your home folder for MSYS. You need to make sure you have your ssh key (id_rsa ?) in the .ssh subfolder (relative to the home folder).
当您直接启动 git bash 时,您将进入 MSYS 的主文件夹。您需要确保 .ssh 子文件夹(相对于主文件夹)中有您的 ssh 密钥(id_rsa ?)。
回答by Henk
Glad you solved the problem. Since this sounds like a serious problem I'm interested in the difference between git-bash when started from GitExtensions. In GitExtensions there is a setting that might fix this. The %HOME% directory can be changed in GitExtensios. By default it will be set to %HOMEDRIVE%%HOMEPATH%, but you can override this. Changing this probably solves your problem, since you suggest this is the problem. To change this open the settings dialog and go to the tab "git". In the section "Environment" you can set the %HOME% path.
很高兴你解决了这个问题。由于这听起来像是一个严重的问题,因此我对从 GitExtensions 启动时 git-bash 之间的区别很感兴趣。在 GitExtensions 中有一个设置可以解决这个问题。%HOME% 目录可以在 GitExtensios 中更改。默认情况下,它将设置为 %HOMEDRIVE%%HOMEPATH%,但您可以覆盖它。更改此设置可能会解决您的问题,因为您认为这就是问题所在。要更改此设置,请打开设置对话框并转到选项卡“git”。在“环境”部分,您可以设置 %HOME% 路径。
I will appreciate it if you let me know if this also solves the problem. I'm also interested in what caused this in the first place. Maybe I can improve the check for a valid HOME directory.
如果您让我知道这是否也解决了问题,我将不胜感激。我也对首先导致这种情况的原因感兴趣。也许我可以改进对有效 HOME 目录的检查。
回答by vkaul11
I see that the HOME variable is set to USERPROFILE in git extensions. I can add and commit but not push/pull from the remote repository. I am unable to connect to any remote repository. We use http (not ssh) for the connection. However, using git bash I am able to connect to the remote and do push/pull. I had put my issue GIT extensions does not connect to remote but git bash doesand was directed to this issue. However, I am unable to resolve my issue. Any ideas?
我看到 HOME 变量在 git 扩展中设置为 USERPROFILE。我可以添加和提交但不能从远程存储库推/拉。我无法连接到任何远程存储库。我们使用 http(而不是 ssh)进行连接。但是,使用 git bash 我能够连接到远程并进行推/拉。我已经提出了我的问题GIT 扩展没有连接到远程但 git bash 可以并被定向到这个问题。但是,我无法解决我的问题。有任何想法吗?