git错误大汇总

来源:互联网 发布:淘宝人员考核标准 编辑:程序博客网 时间:2024/04/28 05:32

为了搭建gitosis,自己折腾了两天,碰到无数问题,那个郁闷,网络上的解答都是零散的,于是把它汇聚一起,并把自己的解决办法和思路放上来,或许有错漏。


1.Untracked working tree file 'external/broadcom/Android.mk' would be overwritten by merge.  Aborting

需要执行下面的命令才能修复:

     git reset --hard HEAD      git clean -f -d      git pull  

2.Please, commit your changes or stash them before you can merge.

如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

git stashgit pullgit stash pop

然后可以使用git diff -w +文件名 来确认代码自动合并的情况.


反过来,如果希望用代码库中的文件完全覆盖本地工作版本. 方法如下:

git reset --hardgit pull

其中git reset是针对版本,如果想针对文件回退本地修改,使用

git checkout HEAD file/to/restore  


3.does not appear to be a git repository

路径错误,可以分别尝试绝对路径或者相对路径

如果是把另一个服务器的纯仓库弄到服务器,也会出现这种情况。我的临时做法是把另一个服务器的内容clone到本地服务器,然后在本地服务器创建纯仓库,放到repository的路径下,就可以了。有关这个错误,我在这篇文章里尝试寻找原因:

http://blog.csdn.net/xzongyuan/article/details/9366873

4.ERROR:gitosis.serve.main:Repository read access denied

修改本地gitosis-admin的gitosis-conf后(如下),push到仓库中,还会遇到该问题

[group customer]
members = nexus b
readonly = box_4.2

原因1 gitosis.conf写错:
gitosis.conf中的members与keydir中的用户名不一致,如gitosis中的members = foo@bar,但keydir中的公密名却叫foo.pub
解决
使keydir的名称与gitosis中members所指的名称一致。

改为members = foo 或 公密名称改为foo@bar.pub


参考
http://blog.csdn.net/lixinso/article/details/6526643

注意,中间如果遇到这样的错误,很可能是gitosis.conf配置的不对
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

有可能是:
1. gitosis 中写的用户名,和keydir里面的key的名字没有完全对应上
2. 有的地方写错了,比如我把members写成了member,汗


原因2 地址错误:

虽然有时候,地址错误时,会提示did not apear to be a git repositry。但我也遇到这个错误,写错了相对路径,就会提示没有权限,因为gitosis.conf根本就没有这个文件的配置嘛。可以看看我的记录:

第一次,写错相对路径,自己不知道:

norton@norton-laptop:~/work$ git clone git@192.168.0.3:/repositories/gitosis-admin.git
Initialized empty Git repository in /home/norton/work/gitosis-admin/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

第二次,故意写个不存在的路径

norton@norton-laptop:~/work$ git clone git@192.168.0.3:/repositories/gitosis-admin.git2
Initialized empty Git repository in /home/norton/work/gitosis-admin.git2/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

第三次,写对相对路径。可见,相对路径的根目录是/home/git/repositories,记得不要多写了不必要的路径。提示一下,repositories是在初始化gitosis前就已经手动建立的,是一个软链接,链接到/home/repo。如果没做这一步,初始化的时候就会建立一个repositories文件夹,那么gitosis-admin这个仓库就会在这个实在的文件夹下,而不会通过软连接放到/home/repo中

norton@norton-laptop:~/work$ git clone git@192.168.0.3:gitosis-admin.git

Initialized empty Git repository in /home/norton/work/gitosis-admin/.git/
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 5 (delta 0), reused 5 (delta 0)
Receiving objects: 100% (5/5), done.

原因3:开错账户

有时候,头脑不清醒了,就会弄错账户,所以犯这个错,要思考下是不是搞错账户了,在主帐号admin中,不断地测试下载,而我的目的其实是用b的帐号测试下载。如配置如下(并没有给admin读取teamwork的权限,而我却一直在clone teamwork)

[gitosis]

[group gitosis-admin]
members = admin
writable = gitosis-admin test

[group RK_Download]
members = b nexus
readonly = teamwork box_4.2 

~                                                                               
~                                   

测试结果

admin@admin:~/work/test$ git clone git@192.168.0.3:test.git
Initialized empty Git repository in /home/admin/work/test/test/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

admin@admin:~/work/test$ git clone git@192.168.0.3:teamwork.git
Initialized empty Git repository in /home/admin/work/test/teamwork/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

admin@admin:~/work/test$ git clone git@192.168.0.3:teamwork.git
Initialized empty Git repository in /home/admin/work/test/teamwork/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

admin@admin:~/work/test$ git clone git@192.168.0.3:teamwork.git
Initialized empty Git repository in /home/admin/work/test/teamwork/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly 


刚记录完,又犯傻逼了,clone 了N次test,都不行,结果发现,自己根本没有把给b设定test的权限。再次说明头脑要清醒。

$ git clone git@192.168.0.3:test.git
Initialized empty Git repository in /tmp/test/.git/
ERROR:gitosis.serve.main:Repository read access denied
fatal: The remote end hung up unexpectedly

修改后
Initialized empty Git repository in /tmp/teamwork/test/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

原因4: 不能写绝对路径

暂时不知道为啥,反正路径写了git@<Server IP>:/home/repo/xxx.git就会出现这个错误。貌似如果你如果密钥验证失败,要求你输入密码的情况下,是输入绝对路径的,而如果密钥验证成功,输入绝对路径,它就不认了。我想,这是为了保证系统安全,不让客户端用git账户乱clone不在repositories下的文件,即限定在repositories下了,所以只能用相对路径。

5.SSH: The authenticity of host <host> can't be established

0 down vote

This message is just SSH telling you that it's never seen this particular host key before, so it isn't able to truly verify that you're connecting to the host you think you are. When you say "Yes" it puts the ssh key into your known_hosts file, and then on subsequent connections will compare the key it gets from the host to the one in the known_hosts file.

There was a related article on stack overflow showing how to disable this warning,http://stackoverflow.com/questions/3663895/ssh-the-authenticity-of-host-hostname-cant-be-established.



6.unrecognized command 'gitosis-serve b' && 每次登录要求输入密码

$ git clone git@192.168.0.3:/home/repo/teamwork.git
Initialized empty Git repository in /home/b/work/teamwork/.git/
fatal: unrecognized command 'gitosis-serve b'
fatal: The remote end hung up unexpectedly

遇到这个问题,b是我一个普通账户,而另一个admin每次登录都要求输入密码(ssh有两种登录方式:要求输入密码,和不需要输入密码——利用密钥),我就怀疑,gitosis的配置已经给我弄乱了,所以无法识别正确的密钥。
这个时候,我已经改了好多次密钥对,gitosis已经配置过好多次。通过gitosis-init是不会修复该问题的,于是,我删掉/home/git/下和repository有关的文件夹,包括.ssh下的authoritykey。还要删掉在/home/repo下的gitosis-admin.git。这样重新gitosis-init一下,就可以了。


如果server端的/etc/passwd中git的账户设置中,git使用的是/usr/bin/git-shell,而不是/bin/sh,也会报这个错误。


7.Agent admitted failure to sign using the key.

通过图形界面切换到b用户时,遇到这个问题,在原来到界面中,su b是可以clone的。


解決方式 使用 ssh-add 指令将私钥 加进来 (根据个人的密匙命名不同更改 id_rsa)
# ssh-add   ~/.ssh/id_rsa 

原创粉丝点击