Git提交失败问题
参考:http://www.jsphp.net/soft/show-31-321-1.html
官方文档:https://git-scm.com/docs
本地已有git项目,重新更换服务端git空的仓库地址时发生问题。
重新定义remote:
git remote add origin git@xxxx.git
推送本地代码到服务器:
git push -u origin master
输出:
To xxxx.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'git@xxxx.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
输出:
remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Total 2 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (2/2), done. From xxxx * [new branch] master -> origin/master There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details. git pull <remote> <branch> If you wish to set tracking information for this branch you can do so with: git branch --set-upstream-to=origin/<branch> master
再次推送还是报错:
git push -u origin master
To xxxx.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@xxxx.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
解决办法,通过强制推送解决:
git push -u origin master -f