2012-06-25 55 views
3

我已经使用了SVN多年,但我想第一次测试Git。Git +智能HTTP问题(无法推/拉)

我试图使用HTTP协议,以保持我以前的凭据(使用htpasswd)。

我跟着我的服务器上执行此过程:

$ aptitude install git-core apache2 
$ mkdir -p /var/git/repositories 
$ htpasswd -c /var/git/passwd my_account 
$ cat > /etc/apache2/sites-available/git << EOF 
<VirtualHost *:80> 
    ServerName git.mydomain.com 

    SetEnv GIT_PROJECT_ROOT /var/git/repositories 
    SetEnv GIT_HTTP_EXPORT_ALL 
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER 

    ScriptAlias//usr/lib/git-core/git-http-backend/ 

    DocumentRoot /var/git/repositories 

    <Directory /var/git/repositories> 
     Options +ExecCGI +SymLinksIfOwnerMatch -MultiViews 
     AllowOverride None 
     Order allow,deny 
     allow from all 
    </Directory> 

    <Location /> 
     AuthType Basic 
     AuthName "Git Access" 
     AuthUserFile /var/git/passwd 
     Require valid-user 
    </Location> 
</VirtualHost> 
EOF 

$ a2ensite git 
$ service apache2 reload 

$ cd /var/git/repositories 
$ git init --bare my_project.git 
$ git update-server-info 

在我的客户,我这样做:

$ git clone http://git.mydomain.com/my_project.git 
$ cd my_project 
$ cat > test-file.txt << EOF 
This is a test 
EOF 
$ git add test-file.txt 
$ git commit -m "My first commit" 

一切似乎现在是好的。

因为我希望我的内容能够通过远程存储库进行更新,所以我做了git pull,但这不起作用。 的Git返回以下消息:

Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.

不管怎样,我独自一人在我的代码。我会稍后尝试修复它。我们尝试推送到服务器。因此我做git push

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date

好了... “无为”“一切都取决于最新的”

一点点检查后,我发现,执行下面的命令:git push origin master 这一次,我有以下消息:

error: unpack failed: unpack-objects abnormal exit
To http://git.mydomain.com/my_project.git
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'http://git.mydomain.com/my_project.git'

我试图按照网络上很多教程。

我觉得我的配置很简单,所以我不明白为什么它不起作用。

感谢任何能够帮助我的人。

编辑:

我从头开始重新启动,以下http://www.kernel.org/pub/software/scm/git/docs/git-http-backend.html

我不需要的GitWeb。我只想用Git客户端使用HTTP协议。

所以我的虚拟主机是:

<VirtualHost *:80> 
    ServerName git.mydomain.com 

    SetEnv GIT_PROJECT_ROOT /var/git/repositories 
    SetEnv GIT_HTTP_EXPORT_ALL 
    SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER 

    ScriptAlias//usr/lib/git-core/git-http-backend/ 

    DocumentRoot /var/git/repositories 

    <Location /> 
     AuthType Basic 
     AuthName "Git Access" 
     AuthUserFile /var/git/passwd 
     Require valid-user 
    </Location> 

</VirtualHost> 

我有完全相同的错误。

git pull回报:

Your configuration specifies to merge with the ref 'master' from the remote, but no such ref was fetched.

git push origin master回报:

error: unpack failed: unpack-objects abnormal exit To http://git.mydomain.com/my_project.git ! [remote rejected] master -> master (n/a (unpacker error)) error: failed to push some refs to 'http://git.mydomain.com/my_project.git'

+2

如果您不使用密码/加密密码,会发生什么情况?作为一个方面说明,不会ssh就够了吗? – Shahbaz

+1

SSH可能够用了,但对于SSH,我应该使用“系统”帐户而不是简单列表或数据库中的帐户,对吧? 如果我只是使用SSH,这个协议将使用户能够连接和执行命令。 – antoine

+0

我用更简单的方式更新了线程来安装GIT服务器。 但它还没有工作。 – antoine

回答

0

我不知道这是答案,但我记得我有类似的问题,因为我没有安装CGI。所以我会以root或者sudo的方式安装依赖项。 (我知道我费口舌这个建议。) 防爆Debian的堆栈:

#!/bin/sh 

apt-get install git-core 
apt-get install curl-ssl 
a2enmod cgi 
a2enmod alias 
a2enmod env 

您可能会丢失Apache的CGI模块。从理论上讲,你的apache cfg文件看起来不错,但我也会尝试将这些脚本别名改为实际名称,而不是仅仅使用根来确保服务器没有做任何疯狂的事情。但我和你在一起。我正试图让Smart GIT HTTP在ubuntu服务器上运行。我将它发布在Debian上,但之前的Apache Rewrite Rules重定向了网址。我不会使用git init --bare。我至少会创建一个自述文件,以便git可以创建一个HEAD。然后使用git init,因为GIT已经标准化了放置.git /文件夹来保存信息。 git init --bare不会这样做。使用git log来查看更改。 例如:

#!/bin/sh 

echo >> '' README 
git init 
git add . 
git commit 
git log --oneline --decorate --graph