Visual Studio 2015 中的 Git (SSH)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31550993/
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
Git (SSH) in Visual Studio 2015
提问by John Mitchell
So with Visual Studio 2015 just being released there is a much more integrated tie-in with git.
因此,在刚刚发布的 Visual Studio 2015 中,与 git 的集成度更高。
However the feature that seems to be lacking is git over SSH. There are various plugins for 2013 that allow this functionality (i.e GitExtensions) but I can't see any with 2015.
然而,似乎缺乏的功能是 git over SSH。2013 年有各种插件允许此功能(即 GitExtensions),但我在 2015 年看不到任何插件。
GitHub plugin only appears to work with GitHub and not generic git repos.
GitHub 插件似乎只适用于 GitHub 而不是通用的 git 存储库。
I'm not looking for an opinion of which is better, only some examples or articles to see if anyone has got Git+SSH on Visual Studio 2015 working.
我不是在寻找哪个更好的意见,只是一些示例或文章,看看是否有人在 Visual Studio 2015 上使用 Git+SSH。
回答by Edward Thomson
No. Visual Studio 2015 (RTM) does not support SSH for Git remotes. This is true even with GitHub repositories using the GitHub plug-in (which - at present - uses the same connection mechanism for Git repositories as any other Git repository using Team Explorer.)
不可以。Visual Studio 2015 (RTM) 不支持 Git 远程的 SSH。即使使用 GitHub 插件的 GitHub 存储库也是如此(目前,它对 Git 存储库使用与使用 Team Explorer 的任何其他 Git 存储库相同的连接机制。)
This is regrettable, but there are a handful of reasons why this is not available yet: the short answer is that in our opinion, providing SSH poorlyor insecurelyis worse than not providing SSH at all, and we would like to be very confident that any SSH implementation we provide is of high-quality.
这是令人遗憾的,但有几个原因导致这还不可用:简短的回答是,在我们看来,糟糕或不安全的SSH 比根本不提供 SSH 更糟糕,我们非常有信心我们提供的任何 SSH 实现都是高质量的。
That said, we are working on it, and making progress. Microsoft is going to begin including OpenSSH in Windows(and is a sponsor of that very fine project). However I cannot make any predictions as to when support might be available.
也就是说,我们正在努力,并取得进展。Microsoft 将开始在 Windows 中包含OpenSSH(并且是那个非常好的项目的赞助商)。但是,我无法对何时可以获得支持做出任何预测。
The GitHub extensionis open source, so it's possible that it may be able to use a different connection mechanism and begin supporting SSH before the core Git support in Team Explorer.
在GitHub的扩展是开源的,所以这是可能的,它可能是能够使用不同的连接机制,并开始在团队资源管理器的核心Git支持前支持SSH。
回答by GSBTom
Here's some basic instructions for Visual Studio Update 2 and Update 3. See the link in BPas' post for the basic stuff, e.g. you'll need:
以下是 Visual Studio Update 2 和 Update 3 的一些基本说明。有关基本内容,请参阅 BPas 帖子中的链接,例如,您需要:
- CMake (I used 3.5.2)
- libssh2 (I used 1.7.0)
- libgit2 source (grab the source from VS 2015 as noted in BPas's link)
- CMake(我用的是 3.5.2)
- libssh2(我用的是 1.7.0)
- libgit2 源(如 BPas 链接中所述,从 VS 2015 中获取源)
Build libssh2
构建 libssh2
- I used libssh2 1.7.0. You can use older, but don't as you'll need to fix some build issues in VS2015.
Do the following:
cd <libssh2 root dir> (e.g. wherever you extracted the source to) mkdir build && cd build cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF ..
Open the resulting libssh2.sln in the build directory
- Set the build type to "Release" (this is important!)
- Edit the libssh2 project, and set the calling type to __stdcall (e.g. /Gz)
- Rebuild all, if successful, the resulting lib will be in build/src/Release/libssh2.lib
- 我使用了 libssh2 1.7.0。您可以使用较旧的,但不要使用,因为您需要修复 VS2015 中的一些构建问题。
请执行下列操作:
cd <libssh2 root dir> (e.g. wherever you extracted the source to) mkdir build && cd build cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF ..
在构建目录中打开生成的 libssh2.sln
- 将构建类型设置为“发布”(这很重要!)
- 编辑libssh2工程,设置调用类型为__stdcall(例如/Gz)
- 全部重建,如果成功,生成的lib将在build/src/Release/libssh2.lib
Build libgit2
构建 libgit2
Do the following:
cd <libgit2 source dir> (e.g. this is wherever you extracted the libgit2 source you got from VS2015's extensions directory, see BPas' link for details) mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release -DSTDCALL=ON -DSTATIC_CRT=OFF -DUSE_SSH=OFF -DLIBSSH2_FOUND=TRUE -DLIBSSH2_INCLUDE_DIRS=<libssh2 root dir>/include -DLIBSSH2_LIBRARIES=<libssh2 root dir>/build/src/Release/libssh2.lib ..
Open the resulting libgit2.sln in the build directory
- Set the build type to "Release"
Optional: Patch src/transports/ssh.c to support SSH RSA key authentication, in function request_creds (around line 444):
if (!t->owner->cred_acquire_cb) { no_callback = 1; } else {
with:
if (!t->owner->cred_acquire_cb) { if (user) { const char *val = NULL; val = getenv("USERPROFILE"); if (val) { char *szprivfilename = malloc(strlen(val) + 128); char *szpubfilename = malloc(strlen(val) + 128); strcpy(szprivfilename, val); strcat(szprivfilename, "/.ssh/id_rsa"); strcpy(szpubfilename, val); strcat(szpubfilename, "/.ssh/id_rsa.pub"); git_cred_ssh_key_new(&cred, user, szpubfilename, szprivfilename, ""); free(szprivfilename); free(szpubfilename); } if (!cred) { giterr_set(GITERR_SSH, "git_cred_ssh_key_new failed to initialize SSH credentials"); return -1; } } else { no_callback = 1; } } else {
Note: this patch was grabbed from one the comments in randomswdev's post, seems to work fine from my limited testing.
- Rebuild All, output is git2.dll, replace libgit2-msvc.dll in your Visual Studio 2015 extensions directory
请执行下列操作:
cd <libgit2 source dir> (e.g. this is wherever you extracted the libgit2 source you got from VS2015's extensions directory, see BPas' link for details) mkdir build && cd build cmake -DCMAKE_BUILD_TYPE=Release -DSTDCALL=ON -DSTATIC_CRT=OFF -DUSE_SSH=OFF -DLIBSSH2_FOUND=TRUE -DLIBSSH2_INCLUDE_DIRS=<libssh2 root dir>/include -DLIBSSH2_LIBRARIES=<libssh2 root dir>/build/src/Release/libssh2.lib ..
在构建目录中打开生成的 libgit2.sln
- 将构建类型设置为“发布”
可选:在 request_creds 函数中修补 src/transsports/ssh.c 以支持 SSH RSA 密钥认证(第 444 行左右):
if (!t->owner->cred_acquire_cb) { no_callback = 1; } else {
和:
if (!t->owner->cred_acquire_cb) { if (user) { const char *val = NULL; val = getenv("USERPROFILE"); if (val) { char *szprivfilename = malloc(strlen(val) + 128); char *szpubfilename = malloc(strlen(val) + 128); strcpy(szprivfilename, val); strcat(szprivfilename, "/.ssh/id_rsa"); strcpy(szpubfilename, val); strcat(szpubfilename, "/.ssh/id_rsa.pub"); git_cred_ssh_key_new(&cred, user, szpubfilename, szprivfilename, ""); free(szprivfilename); free(szpubfilename); } if (!cred) { giterr_set(GITERR_SSH, "git_cred_ssh_key_new failed to initialize SSH credentials"); return -1; } } else { no_callback = 1; } } else {
注意:这个补丁是从 randomswdev 帖子中的评论中抓取的,从我有限的测试来看似乎工作正常。
- 全部重建,输出为 git2.dll,替换 Visual Studio 2015 扩展目录中的 libgit2-msvc.dll
回答by Vladimir Koltunov
Conforming to BPas: for Visual Studio 2015 it is possible to build SSH enabled version. Moreover, i have patch for public/private key auth support:
符合 BPas:对于 Visual Studio 2015,可以构建支持 SSH 的版本。此外,我有用于公钥/私钥身份验证支持的补丁:
回答by BPas
It is possible to enable ssh support by recompiling the GIT library distributed with Visual Studio 2015. The following article describes the required steps:
可以通过重新编译 Visual Studio 2015 分发的 GIT 库来启用 ssh 支持。 以下文章描述了所需的步骤:
http://randomswdev.blogspot.it/2015/07/adding-ssh-support-to-visual-studio.html
http://randomswdev.blogspot.it/2015/07/adding-ssh-support-to-visual-studio.html
回答by BPas
There used to be nonsense here about adding your git to visual studio using the git bash. Even though adding would work, creating commits was also an option but syncing them would still require the git bash. So this would be kinda useless.
关于使用 git bash 将您的 git 添加到 Visual Studio,这里曾经是无稽之谈。即使添加可以工作,创建提交也是一种选择,但同步它们仍然需要 git bash。所以这有点没用。