yuanrui / blog

Some notes.
http://yuanrui.github.io
3 stars 0 forks source link

解决VS2017克隆TFS git库失败问题 #21

Open yuanrui opened 5 years ago

yuanrui commented 5 years ago

tfs2018支持创建git代码库,使用vs2017克隆,遇到一个奇怪的问题。 git_failed_with_a_fatal_error 使用网上的一些教程,始终无法有效的克隆代码。tfs2018提供在命令行中配置ssh的方式克隆代码库,参考msdn教程,基本解决问题。 需要说明的是,如果ssh URL中存在中文会将中文进行编码处理。 git_ssh_cmd 安装msdn教程设置ssh key. https://docs.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops 完成后使用git clone命令克隆代码,命令如下: git clone ssh://url.... git_clone 在Windows资源管理器中,显示的文件夹名称是编码后的中文,可以重命名为中文。 image

20190816更新: 在更新到最新版本的VS后,出现拉取代码失败的情况。

Warning: Pulling without specifying how to reconcile divergent branches is
Git failed with a fatal error.
Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

正在从 origin 提取
提取时遇到错误: Git failed with a fatal error.
Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

未能从远程存储库提取。请参见输出窗口了解更多详细信息。
Warning: Pulling without specifying how to reconcile divergent branches is
Git failed with a fatal error.
Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决办法: 1、从Git官网下载32位便携版。 32-bit Git for Windows Portable 2、替换C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git,替换前注意备份。 3、重启VS和电脑。

20210323更新: 最近更新git后又出现了新的问题,clone提示秘钥交换算法不一致。

Unable to negotiate with fe80::8436:e651:6655:2e81%11 port 22: no matching key e
xchange method found. Their offer: diffie-hellman-group1-sha1,diffie-hellman-gro
up14-sha1
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决方法: 1、设置Git全局配置

git config --global user.name "yourname"
git config --global user.email "youremail@xxx.com"

2、在Git安装目录下找到ssh-keygen.exe,重新生成RSA秘钥对。

ssh-keygen.exe -t rsa -C "youremail@xxx.com"

3、在TFS的"SSH 公钥"处添加 C:\Users\当前登录用户.ssh\id_rsa.pub文件的内容。 4、编辑.ssh目录下的config文件,如果不存在则用记事本创建一个(注意该文件无后缀),添加如下内容

Host *
    KexAlgorithms +diffie-hellman-group1-sha1

20240513更新: 安装git-2.45 64位版本后,出现这个问题

Unable to negotiate with 192.168.1.75 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1
Git failed with a fatal error.
Git failed with a fatal error.
Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

在config文件中添加如下配置:

Host 192.168.1.75
    Port 22
    IdentityFile C:\Users\YuanRui\.ssh\id_rsa.pub
    HostKeyAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa
    KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1

Host *
    HostKeyAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa
    KexAlgorithms +diffie-hellman-group1-sha1,diffie-hellman-group14-sha1

由于本地没有安装nodejs,导致出现如下问题。

.git/hooks/pre-push: line 32: node: command not found

临时办法,在项目文件夹中删除 pre-push