git所遇问题

git一些问题

(1)

teisei@john:~/git/helloworld$ git push -u origin master
Username for 'http://58.198.176.136': teisei
Password for 'http://teisei@58.198.176.136': 
To http://58.198.176.136/teisei/helloworld.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'http://58.198.176.136/teisei/helloworld.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
问题原因:git仓库中已经有一部分代码,所以他不允许拟直接把你的代码覆盖上去。于是拟由两个选择:

1.强推,即利用强覆盖方式用你本地的代码体改git仓库内的内容

git push -g origin master

2.先把git的东西fetch到你本地然后merge后在push

git fetch

git merge

这两句命令等价与

git pull


(2)

teisei@john:~/git/ecnuNLP$ git push origin master
Username for 'http://58.198.176.136': teisei
Password for 'http://teisei@58.198.176.136': 
Counting objects: 13, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (11/11), done.
error: RPC failed; result=22, HTTP code = 413 31 MiB/s   
fatal: The remote end hung up unexpectedly
Writing objects: 100% (11/11), 58.30 MiB | 14.43 MiB/s, done.
Total 11 (delta 1), reused 0 (delta 0)
fatal: The remote end hung up unexpectedly
Everything up-to-date


用http或httpp方式提交git里大批量的数据更改时,你可能会遇到这样的错误。因为Git默认设置最大的http传输量卫1MB。

可以通过:

git config http.postBuffer *bytes*

git config http.postBuffer 524288000

来修改可传输字节最大值



1 error:src refspec master does not match any

问题产生

a git服务器使用如下命令新建一个项目

1cd /opt/git
2mkdir project.git
3cd project.git
4$ git --bare init
b 客户端clone代码并提交
1cd myproject
2$ git init
3$ git add .
4$ git commit -m 'initial commit'
5$ git remote add origin git@gitserver:/opt/git/project.git
6$ git push origin master

c push报错 

Git 常见问题整理

原因分析

引起该错误的原因是,目录中没有文件,空目录是不能提交上去的

解决办法

1touch README
2git add README 
3git commit -m 'first commit'
4git push origin master

2 fatal: unable to connect to eagain.net

问题产生

使用git clone 命令从 eagain.net 克隆gitosis.git源码出错

解决办法

1git clone git://github.com/res0nat0r/gitosis.git

3 fatal:Interactive git shell is not enabled

问题产生

a 设置git用户登录shell

作为一个额外的防范措施,你可以用Git 自带的git-shell 简单工具来把git 用户的活动限制在仅与Git 相关。把它设为git 用户登入的shell,那么该用户就不能拥有主机正常的shell 访问权。为了实现这一点,需要指明用户的登入shell 是git-shell ,而不是bash 或者csh。你可能得编辑/etc/passwd 文件:

1sudo vim /etc/passwd

找到git用户的信息,修改如下:

Git 常见问题整理

保存修改后,使用如下命令访问服务器

1ssh git@gitserver

报错如下:

Git 常见问题整理

原因分析

按照提示,在git用户的主目录下面需要存在git-shell-commands目录

解决办法

在git用户的主目录下面新建git-shell-commands目录

参考链接

http://planzero.org/blog/2012/10/24/hosting_an_admin-friendly_git_server_with_git-shell

4 通过http协议clone出错

问题产生

在gitserver通过apache提供了git项目的公共访问地址,在克隆的时候报错如下:

Git 常见问题整理

解决办法

在git服务器上要提供的项目下面执行

1git update-server-info

 centos5.8下面安装gitweb的默认路径问题

问题产生

在centos下使用yum install gitweb 命令安装gitweb后找不到gitweb的默认安装路径

原因分析

网络上的说法默认路径是 /var/www/git ,但是在我的centos虚拟机中,安装完gitweb后,默认路径是/usr/share/gitweb

解决办法

由于按网上的说法,找不到gitweb的默认安装路径,我使用了find 命令,用来查找gitweb所在的目录

6 安装gitosis时使用python3.3.0执行python setup.py install 报错

问题产生

在安装gitosis的时候,需要预先安装工具包python-setuptools,安装命令比较简单

1yum install python-setuptools

但是在clone了gitosis代码,执行python安装命令的时候报错,错误提示如下:

ImportError: No module named setuptools

原因分析

1<span>网上摘要 </span>Your setup.py file needs setuptools. Many of the Python packages use distutils forthe distribution, but some use setuptools, a morecomplete package. Here is a question about the differences between them.Regarding Python 3.3, you should installdistribute instead. It is a more recent package that works inthe same way as setuptools (it's even called setuptools internally).
2 
3链接地址:
4http://stackoverflow.com/questions/14426491/python-3-importerror-no-module-named-setuptools

centos默认的python版本是2.4.3,因为一次机会我升级了python的版本到3.3.0,这样就出现了错误。

解决办法

我的办法是降低了python的版本,有兴趣的同学可以尝试安装distribute包,看能不能解决这个问题

7 git push origin master 到github出错

问题产生

本地项目添加了远程仓库,但是在推送代码到远程仓库的时候,报无法连接到远程服务器

原因分析

github和本地代码做推送和拉取时,需要用到ssh的密钥对进行数据加解密,由于github上新建的项目没有添加密钥,所以本地仓库连接不到远程仓库

解决办法

在github上为该项目添加公钥,推荐做法是不要单独为每个项目添加公钥,而是直接通过github帐号的ssh信息维护开发机的ssh公钥



版权声明:本文为Teisei11原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。