msysgit troubles

风格不统一 提交于 2019-12-19 06:43:51

问题


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

ssh://user@host:port

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

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

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

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

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

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

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


回答1:


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: Since you can connect using putty, looks like ssh is setup ok.

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

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.

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.

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://user@host.com: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

5: Setting up public/private key for 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_dsa and id_dsa.pub from 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)

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

git clone ssh://user@host.com:port/home/source_code/test_repo.git

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




回答2:


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

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




回答3:


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

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

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

git push URL master



回答4:


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

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 -i keyfile user@host:port

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.



来源:https://stackoverflow.com/questions/1497932/msysgit-troubles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!