Git 使用 Cygwin 推送到远程服务器挂起

Git Push To Remote Server Hangs Using Cygwin

我是通过命令行 git 的新手,运行 遇到了一些我一直无法摆脱的麻烦。

我已经在我的服务器上设置了一个存储库,并使用 thelucid.com 中的说明创建了一个本地目录。

在服务器上:

ssh git@example.com
mkdir my_project.git
cd my_project.git
git init --bare
git update-server-info # If planning to serve via HTTP
exit

然后,在本地机器上:

cd my_project
git init
git add *
git commit -m "My initial commit message"
git remote add origin git@example.com:my_project.git
git push -u origin master

当我到达这里的最后一个命令时 "git push -u origin master" 命令挂起并挂起,永远不会停止挂起。

git 本地状态给了我这个:

$ git status
On branch master
nothing to commit, working directory clean

git 服务器上的状态(在 myproject.git/ 内)给我:

$ git status
fatal: This operation must be run in a work tree

我不确定下一步该去哪里,我已经尝试了很多东西,但我的无知是多山的,我可以使用指南;如果您有备用的话,也许是巫师,一些矮人和霍比特人。任何帮助将不胜感激。

我在 windows 8.1。 使用 Cygwin

谢谢。

问题是您在 .git 文件夹中。 您需要在根文件夹(.git 的父文件夹)中才能查看状态,然后推送所有更改。

cd..
git status

如果您正在使用 Windows,msysgit is a better option. Using git push in Cygwin is known to have issues. The gist of it is that Git by default, tries to use a "simple password prompt" as part of its user authentication process, as mentioned in the git-config doc(search for core.askpass). This password prompt, however, only works on real UNIX, but not on Cygwin. If interested, you can read about the history of this issue here

如果您绝对必须使用 Cygwin,请确保按照指定 here 安装了 Cygwin git 软件包。然后尝试 运行 这个命令:

$ git config --global core.askpass /usr/libexec/git-core/git-gui--askpass

可能还有其他更复杂的解决方案,但我认为最简单的解决方案仍然是安装 msysgit。 :-)