今天把代码提交仓库的时候,远程push的时候报错了

遇到的问题

![rejected] master -> master (fetch first) error: failed to push some refs

我是这么操作的

git add .
git commit -m "更新了代码"
git push monitor master

命令行是这么报错的

To https://gitee.com/handsomewood/Monitor.git
! [rejected]        master -> dev-gaochao (fetch first)
error: failed to push some refs to 'https://gitee.com/handsomewood/Monitor.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.

报错原因

之所以出现这个原因,是因为我在线上生成、编辑了README.md文件,而本地代码文件中不包含它,所以线上线下就对不上了。

解决方法

进行代码合并

git pull --rebase monitor master

成功:

Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
remote: Create a pull request for 'master' on Gitee by visiting:
remote:     https://gitee.com/handsomewood/Monitor/pull/new/handsomewood:master...handsomewood:v2.0.0
To https://gitee.com/handsomewood/Monitor.git
* [new branch]      master -> master
最后修改:2020 年 08 月 06 日 03 : 30 AM