Git常见问题汇总

error: failed to push some refs to错误处理

最近在看爬虫相关的书,想把其中一本的源码放到github上方便管理。不过在操作的时候有些失误:在github上创建库的时候加上了readme.md选项,但是发现创建的本地库里面也有一个readme.md文件,于是就把github 库里的文件在页面上删除了。因为上述失误操作,在提交代码到远程库的时候报如下错:

george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master  git push -u origin master
To https://github.com/zhiyanzhiyu/wswp.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/zhiyanzhiyu/wswp.git'
...
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

查了一下,说可以先pull在push,但是试了一下pull的时候报错:

george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master  git pull origin master
warning: no common commits
remote: Enumerating objects: 5, done.
...
fatal: refusing to merge unrelated histories
 ✘ george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp 

继续查,有同学说可以通过命令git pull --rebase origin master进行代码合并,这样pull的效果等同于fetch+merge,试了一下,果然可以!

 george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master  git pull --rebase origin master
From https://github.com/zhiyanzhiyu/wswp
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: init submit
 george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master 
 george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master  git push -u origin master
Enumerating objects: 180, done.
...
Branch 'master' set up to track remote branch 'master' from 'origin'.
george@GeorgeMBP  ~/Developer/GitRepos/book-source-code/wswp   master 

你可能感兴趣的:(Git常见问题汇总)