Git 常見問題整理
在學習git的過程中,遇到如下問題,特整理如下:
1 error:src refspec master does not match any
問題產生
a git服務器使用如下命令新建一個項目
$ cd /opt/git $ mkdir project.git $ cd project.git $ git --bare initb 客戶端clone代碼并提交
$ cd myproject $ git init $ git add . $ git commit -m 'initial commit' $ git remote add origin git@gitserver:/opt/git/project.git $ git push origin master
c push報錯
原因分析
引起該錯誤的原因是,目錄中沒有文件,空目錄是不能提交上去的
解決辦法
touch README git add README git commit -m 'first commit' git push origin master
2 fatal: unable to connect to eagain.net
問題產生
使用git clone 命令從 eagain.net 克隆gitosis.git源碼出錯
解決辦法
git 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 文件:
sudo vim /etc/passwd
找到git用戶的信息,修改如下:
保存修改后,使用如下命令訪問服務器
ssh git@gitserver
報錯如下:
原因分析
按照提示,在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 update-server-info
5 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,安裝命令比較簡單
yum install python-setuptools
但是在clone了gitosis代碼,執行python安裝命令的時候報錯,錯誤提示如下:
ImportError: No module named setuptools
原因分析
網上摘要 Your setup.py file needs setuptools. Many of the Python packages use distutils for the distribution, but some use setuptools, a more complete package. Here is a question about the differences between them.Regarding Python 3.3, you should install distribute instead. It is a more recent package that works in the same way as setuptools (it's even called setuptools internally).
鏈接地址:
http://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公鑰