執行:
git push
出現:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/.....'hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
背景:
1、一般是在git上創建了一個倉庫,想把自己已有的項目推到git上,在git add . 和git commit -m "xxx"後git push 失敗
2、在嘗試按照提示git pull時又出現
U .gitignore
A README.md
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
解決辦法:
按照提示 fix them ,問題是怎麼fix them。
1、你提示打開文件(是以項目的根目錄爲起始目錄的)
U .gitignore
A README.md
2、你會看到裏面會有<<<<<<和=======和>>>>>>>
其中<<<<<<<(七個小於號)和=======(七個等於號)之間的是當前分支的內容,=======(七個等於號)和>>>>>>>(七個大於號)之間的內容是合併的分支的內容。此時需要人工判斷保留哪些內容,修改完成後,再將文件提交在暫存區(add操作),再commit到版本庫就解決衝突了,然後就可以pull,最後就可以push了
其實整個過程就是要把你遠程和本地的項目合併,開始的時候如下圖:
master是本地分支master ;laisx/master是遠程分支master(默認是origin/master)
搞完上面的一切就成了: