Git error: src refspec master does not match any. 錯誤處理辦法

原博主地址:http://www.cnblogs.com/jeremylee/p/5715289.html

本地倉庫使用如下命令初始化:

$ git init

之後使用如下命令添加遠程庫:

$ git remote add origin [email protected]:hahah/ftpmanage.git

然後使用

$ git push -u origin master

出現如下錯誤:

error: src refspec master does not match any.
error: failed to push some refs to '[email protected]:hahaha/ftpmanage.git'

原因:

本地倉庫爲空

解決方法:使用如下命令 添加文件;

$ git add add.php addok.php conn.php del.php edit.php editok.php ftpsql.sql index.php

$ git commit -m "init files"

之後在push過程中出現如下錯誤:

複製代碼
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address 'xx.xx.xxx.xxx' to the list of known hosts.
To [email protected]:hahaha/ftpmanage.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to '[email protected]:hahahah/ftpmanage.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
複製代碼

提示使用 git pull 之後在 push

使用如下命令解決:

複製代碼
$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:hahah/ftpmanage
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: init files
複製代碼

繼續push,成功。

複製代碼
$ git push -u origin master
Counting objects: 10, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 5.15 KiB | 0 bytes/s, done.
Total 10 (delta 3), reused 0 (delta 0)
To [email protected]:hahaha/ftpmanage.git
   a2b5c30..1044f15  master -> master
Branch master set up to track remote branch master from origin.

問題二:Git 提示fatal: remote origin already exists 錯誤解決辦法

先刪除遠程 Git 倉庫:git remote rm origin,在執行上面的操作步驟。

問題三: 執行git push出現"Everything up-to-date"

在github上git clone一個項目,在裏面創建一個目錄,然後git push的時候,出現報錯"Everything up-to-date"


原因:
1)沒有git add .
2)沒有git commit -m "提交信息"
如果上面兩個步驟都成功執行,還出現這個錯誤是因爲創建的目錄下是空的,目錄下必須有文件才能git push上傳成功。

在github上創建文件的時候,在新文件名後加/符號就是文件夾,但是這種方式只支持英文名目錄,中文名目錄不支持。


將項目添加到git正確步驟:(親試成功的,不過我是個人開發)

1、在git上創建一個項目

2、在本地新建一個文件夾,然後執行命令:

    1.git init

    2.git remote add origin https://gitee.com/TangJian211085/RectificationSystemTest.git

    3.git pull --rebase origin master

    4.將已有項目的代碼複製到該新建的文件夾下

    5.git add --all

    6.git commit -m '提交描述'

    7.git push -u origin master

3. 其實可以只需在已有項目文件下執行(1、2、3、5、6、7)命令即可(同樣親試過)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章