使用GIT遇见的坑

  今天,就在今天,在使用git 对源代码进行push到gitHub时出错,信息如下

$ git push origin master
To https://github.com/XXXXXX/xxxxxxx.git(自己的代码库)
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/XXXXXX/xxxxxxx.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.

尝试下面的命令把当前分支代码上传到master分支上。

$ git push -u origin master

但依然没能解决问题

然后各种百度,google,看官方文档

 

  出现错误的主要原因是github中的README.md文件不在本地代码目录中 

解决办法:

  可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

  执行上面代码后可以看到本地代码库中多了README.md文件

$ git pull --rebase origin master
warning: no common commits
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/24python/VideoOnline
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: 已完成课程列表接口,课程详情接口,文章列表接口,文章详情接口,点赞接口,收藏接口。
.git/rebase-apply/patch:5717: new blank line at EOF.
+
.git/rebase-apply/patch:5755: new blank line at EOF.
+
.git/rebase-apply/patch:7939: new blank line at EOF.
+
warning: 3 lines add whitespace errors.
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...

  此时再执行语句

git push -u origin master

  即可完成代码上传到github

Counting objects: 41, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (35/35), done.
Writing objects: 100% (41/41), 177.53 KiB | 1.87 MiB/s, done.
Total 41 (delta 0), reused 0 (delta 0)
To https://github.com/24python/VideoOnline.git
   3d5fa8d..e9704fb  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

 

posted @ 2018-06-05 16:05  TheLand  阅读(1199)  评论(0编辑  收藏  举报