Visual Studio 2015中的Git (SSH)

44

随着Visual Studio 2015的发布,git集成更加紧密。

然而,似乎缺少的功能是通过SSH使用git。有多种2013插件可允许此功能(如GitExtensions),但我在2015中找不到这样的插件。

GitHub插件似乎只能用于GitHub而非一般的git仓库。

我不是要求评价哪个更好,只希望能看到一些示例或文章,以查看是否有人已经使Git+SSH在Visual Studio 2015上工作。

5个回答

49

不支持SSH进行Git远程操作,这在Visual Studio 2015(RTM)中是不可用的。即使使用GitHub插件连接GitHub仓库时(目前使用与Team Explorer相同的Git仓库连接机制),也是如此。

这是令人遗憾的,但有一些原因说明为什么还未提供此功能:简短的答复是,在我们看来,提供SSH的质量差或不安全比不提供SSH更糟糕,我们希望确保提供的任何SSH实现都具有高质量。

也就是说,我们正在努力,并取得了进展。微软将开始在Windows中包含OpenSSH(并且是该项目的赞助商)。但是我无法预测何时会提供支持。

GitHub插件是开源的,因此可能可以使用不同的连接机制,并开始在Team Explorer之前支持SSH。


1
@JohnMitchell 确实 - 我猜测GitHub扩展将会更新,以支持与Team Explorer无关的功能,并且我已经更新了我的答案以更好地反映这一点。 - Edward Thomson
5
听起来他们让一些IE的开发人员参与到了VS的开发中... :( - Alex McMillan
3
@aateeque没有改变。 :( - Edward Thomson
1
他们避免了“提供SSH不良或不安全”,但是通过未包含SSH来提供GIT,做得不好。 - Ronnie Overby
2
2017年,微软可以在Windows 10中包含Ubuntu,但仍然不支持Visual Studio中的ssh?得了吧。。 - Edward J Beckett
显示剩余7条评论

7
以下是Visual Studio Update 2和Update 3的基本说明。请查看BPas帖子中的链接获取基础知识,例如您需要使用以下内容:
  • CMake(我使用的是3.5.2)
  • libssh2(我使用的是1.7.0)
  • libgit2源代码(按照BPas链接中的提示从VS 2015中获取源代码)
构建libssh2
  1. I used libssh2 1.7.0. You can use older, but don't as you'll need to fix some build issues in VS2015.
  2. 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 ..
    
  3. Open the resulting libssh2.sln in the build directory

  4. Set the build type to "Release" (this is important!)
  5. Edit the libssh2 project, and set the calling type to __stdcall (e.g. /Gz)
  6. Rebuild all, if successful, the resulting lib will be in build/src/Release/libssh2.lib

构建libgit2

  1. 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 ..
    
  2. Open the resulting libgit2.sln in the build directory

  3. Set the build type to "Release"
  4. 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.

  5. Rebuild All, output is git2.dll, replace libgit2-msvc.dll in your Visual Studio 2015 extensions directory

构建libgit2,应使用Release libssh2<libssh2根目录>/build/src/Release/libssh2.lib。 - Boler
@GSBTom 我不太理解"编辑 libssh2 项目,并将调用类型设置为 __stdcall (例如 /Gx)"这部分。我是一个 C# 程序员,所以我不太明白这一点。 - Gaz83
@GSBTom,非常好的指导!让我离成功更近了一步,但是编译(链接?)libgit2时出现了一堆“未解决的外部符号”,所有这些都是像“_lib_agent_init”和其他函数。我可以在VS中的libssh2.h中看到它们被定义,但就像那些函数的“源”没有被找到一样,尽管libssh2.lib看起来构建正确(没有错误,文件大小为376KB)。有什么建议吗? - jimtut
@jimtut:已经有一段时间没有做这个了(除了为Update 3重新编译libgit2),但是按照说明应该可以工作。我建议使用我使用的libssh2和CMake版本(我注意到在旧版本的libssh2构建中,我编译和链接时遇到了问题,新版本可能会有问题)。确保使用相同的构建配置(我对两者都使用了“Release”)。 - GSBTom

4

3

0

这里曾经有一些关于使用git bash将你的git添加到Visual Studio的无意义内容。 尽管添加是可行的,但创建提交也是一个选项,但同步它们仍然需要使用git bash。 所以这样做有点无用。


但是,如果要进行推送、拉取、同步等操作,难道不需要进入 Git Bash 吗? - John Mitchell
1
抱歉,太晚了我没有注意到,只是添加了提交但没有同步。非常抱歉。 - user5895940

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接