git提交程式碼問題解決
阿新 • • 發佈:2019-01-26
問題:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/NULLcaption/project.git'
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.
核心問題:
Updates were rejected because the tip of your current branch is behind its remote counterpart. Integrate the remote changes (e.g.’git pull …’) before pushing again.
其實質就是原生代碼和遠端程式碼倉庫的專案不一致,解決這個問題,有以下幾種辦法:
1.使用強制push的方法:
$ git push -u origin master -f
這樣會使遠端修改丟失,一般是不可取的,尤其是多人協作開發的時候。
2.push前先將遠端repository修改pull下來
$ git pull origin master
$ git push -u origin master
3.若不想merge遠端和本地修改,可以先建立新的分支:
$ git branch [name]
然後push