git msysgit 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1497932/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:52:20  来源:igfitidea点击:

msysgit troubles

gitsshmsysgit

提问by daniel

So I seem to have some real issues setting up msysgit. I can connect via putty to my SSH directory using

所以我似乎在设置 msysgit 时遇到了一些实际问题。我可以使用 putty 连接到我的 SSH 目录

ssh://user@host:port

ssh://user@host:port

And I have the correct keys. I can also do this using plink via the

我有正确的钥匙。我也可以使用 plink 通过

plink -P PORT user@host -i /path/to/private_key.ppk

plink -P PORT user@host -i /path/to/private_key.ppk

When I attempt to run (via TortiseGIT) or via a git bash

当我尝试运行(通过 TortiseGIT)或通过 git bash

git clone ssh://user@host:port/path/to/myapp.git

git clone ssh://user@host:port/path/to/myapp.git

I just keep getting the error

我只是不断收到错误

Initialized empty Git repository in D:/Git/myapp.git
warning: You appear to have cloned an empty repository.
fatal: The remote end hung up unexpectedly

在 D:/Git/myapp.git 中初始化空 Git 存储库
警告:您似乎克隆了一个空存储库。
致命:远端意外挂断

I have checked bot /Git/setup.ini and TortiseGIT and both use

我已经检查过 bot /Git/setup.ini 和 TortiseGIT 并且都使用

C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe

C:\Program Files\TortoiseSVN\bin\TortoisePlink.exe

Does anyone know how I can fix this problem as its driving me nuts!

有谁知道我该如何解决这个问题,因为它让我发疯了!

回答by daniel

Here is a bit of a check list:

这是一个检查清单:

  1. Is ssh enabled on the server you are trying to connect to?
  2. Is GIT installed on the server?
  3. Do you have a Git repository set-up on the server?
  4. Does the repository the correct permissions and have sharedrepository enabled in the config on the server?
  5. Do you have the ssh keys in the right place for GIT?

    Suggestions:

  1. 您尝试连接的服务器上是否启用了 ssh?
  2. 服务器上是否安装了GIT?
  3. 您是否在服务器上设置了 Git 存储库?
  4. 存储库是否具有正确的权限并在服务器的配置中启用了共享存储库?
  5. 您在 GIT 的正确位置拥有 ssh 密钥吗?

    建议:

1: Since you can connect using putty, looks like ssh is setup ok.

1:由于可以使用putty连接,看起来ssh设置正常。

2: Use putty and connect to the server. Type in git --versionDo you get back a reasonable response? If not then you will need to install it on the server.

2:使用putty连接服务器。输入 git --version您是否得到合理的答复?如果没有,那么您需要在服务器上安装它。

3:Try setting up a new repository on the server. Assuming its a *nix style server use putty and connect to the server and make a new repository using the following commands, assuming you have a directory /home/source_code. The echo line just makes a file with a little bit of text in it so we have something to start with.

3:尝试在服务器上设置一个新的存储库。假设它是一个 *nix 风格的服务器,使用 putty 并连接到服务器并使用以下命令创建一个新的存储库,假设您有一个目录 /home/source_code。echo 行只是创建一个包含一些文本的文件,所以我们有一些东西可以开始。

cd /home/source_code
mkdir test_repo
cd /home/source_code/test_repo
echo "first file" > t.txt
git init
git add .
git commit -m "Initial Import"

So now we have a repository with one t.txt file in it. As a rule you should never push into a repository that contains changes to the working copy. The purpose of having a repository on the server is so that people can push into it all the time. We make a "bare" clone which is only the git database, that way there is no possibility of any working copy changes. It is this "bare" clone that we will use as the central git repository.

所以现在我们有一个存储库,其中包含一个 t.txt 文件。作为规则,您永远不应该推送到包含对工作副本进行更改的存储库。在服务器上有一个存储库的目的是让人们可以一直推入它。我们制作了一个“裸”克隆,它只是 git 数据库,这样就不会有任何工作副本更改的可能性。我们将使用这个“裸”克隆作为中央 git 存储库。

cd /home/source_code
git clone --bare test_repo/ test_repo.git

You can now get rid of the temporary repository that we set up.

您现在可以摆脱我们设置的临时存储库。

cd /home/source_code/
rm -rf test_repo

On your local computer try cloning again

在您的本地计算机上再次尝试克隆

git clone ssh://[email protected]:port/home/source_code/test_repo.git

4: Permissions: This should not cause a problem with cloning, fetching or pulling, unless you have selected a location for the repository that doesnt have read access. If you get a Permission denied error when pushing back then refer to Permissions correction

4:权限:这应该不会导致克隆、获取或拉取问题,除非您为没有读取访问权限的存储库选择了一个位置。如果您在推回时收到权限被拒绝的错误,请参阅权限更正

5: Setting up public/private key for GIT:

5:为GIT设置公钥/私钥:

  1. Connect to the server with putty
  2. Set permissions on your ~/.ssh folder: chmod 700 .ssh
  3. Set permissions on your ~/.ssh/authorized_keys: chmod 600 authorized_keys
  4. Generate the keys ssh-keygen -t dsa
  5. Accept the file names it wants to use
  6. Don't enter a passphrase (just enter). You will want to redo do this with a passphrase later.
  7. add the pub key to the authorized_keys file: cat id_dsa.pub >> .ssh/authorized_keys
  8. edit /etc/ssh/ssh_config and add the line PubkeyAuthentication yes
  9. restart the ssh daemon sudo /etc/init.d/ssh restart
  10. Copy id_dsaand id_dsa.pubfrom the server to your local hard drive (use winscp or sftp or some such tool) c:\users\userName\.ssh directory (this is for vista the location will be a bit different for other versions of windows)
  11. Set tortoise git to point to C:\Program Files\Git\bin\ssh.exe (not putty)
  1. 用putty连接服务器
  2. 设置 ~/.ssh 文件夹的权限: chmod 700 .ssh
  3. 在您的 ~/.ssh/authorized_keys 上设置权限: chmod 600 authorized_keys
  4. 生成密钥 ssh-keygen -t dsa
  5. 接受它想要使用的文件名
  6. 不要输入密码(只需输入)。稍后您将需要使用密码重做此操作。
  7. 将公钥添加到authorized_keys 文件中: cat id_dsa.pub >> .ssh/authorized_keys
  8. 编辑 /etc/ssh/ssh_config 并添加行 PubkeyAuthentication yes
  9. 重新启动 ssh 守护进程 sudo /etc/init.d/ssh restart
  10. 复制id_dsaid_dsa.pub从服务器复制到您的本地硬盘驱动器(使用 winscp 或 sftp 或某些此类工具) c:\users\userName\.ssh 目录(对于 vista 而言,该位置对于其他版本的 windows 会有所不同)
  11. 设置 tortoise git 指向 C:\Program Files\Git\bin\ssh.exe(不是 putty)

Both the command line git and tortoise git should be setup to work. Try cloning again on your local machine.

命令行 git 和 tortoise git 都应该设置为工作。在本地机器上再次尝试克隆。

git clone ssh://[email protected]:port/home/source_code/test_repo.git

You might now want to go and repeat setting up the keys with a passphrase....

您现在可能想要使用密码重复设置密钥....

回答by nolim1t

You need to install Pageant and add the key into it.

您需要安装 Pageant 并将密钥添加到其中。

Also double check that your GIT_SSH environment variable is set up to use plink

还要仔细检查您的 GIT_SSH 环境变量是否设置为使用 plink

回答by nolim1t

Is there anything (i.e. at least one commit) in the remote repo ?

远程仓库中是否有任何内容(即至少一次提交)?

git says: "warning: You appear to have cloned an empty repository"

git 说:“警告:您似乎克隆了一个空存储库”

and when you want to push into the empty remote repo you have to use:

当你想推入空的远程仓库时,你必须使用:

git push URL master

回答by naven87

Have you tried connecting from Git-Bash with ssh user@host:port? Does it connect directly or ask for a password?

您是否尝试过使用 ssh user@host:port 从 Git-Bash 连接?它是直接连接还是要求输入密码?

Port is only required if you are using a non-standard port for ssh otherwise it will default to 22. It is one thing from Putty but make sure you can connect from git bash because it will generally have its own key store in a .ssh directory off of your user directory. If you cannot get that to work from Git-Bash you need to fix the key or debug where the problem is, try specifying the key by using

仅当您为 ssh 使用非标准端口时才需要端口,否则它将默认为 22。这是来自 Putty 的一件事,但请确保您可以从 git bash 连接,因为它通常在 .ssh 中有自己的密钥存储目录关闭您的用户目录。如果您无法从 Git-Bash 获得它,您需要修复密钥或调试问题所在,请尝试使用指定密钥

ssh -i keyfile user@host:port

ssh -i 密钥文件用户@主机:端口

if that doesn't work or prompts you for a password on the remote machine it means the key exchange is not working properly. So you need to go through checking the keys are setup properly with regards to the Git-Bash environment. In particular make sure that you have exported the RSA key and are not just using the ppk key with Git-Bash. I do not believe that is supported. I don't use Tortoise-Git so I can't help with that, but I do use Git Bash regularly.

如果这不起作用或提示您在远程机器上输入密码,则表示密钥交换工作不正常。因此,您需要检查是否针对 Git-Bash 环境正确设置了密钥。尤其要确保您已导出 RSA 密钥,而不仅仅是在 Git-Bash 中使用 ppk 密钥。我不相信这是支持的。我不使用 Tortoise-Git,所以我无能为力,但我确实经常使用 Git Bash。