报错:
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.
原因:
其他地方向同一远端库推送了代码,导致本地不是最新的。
解决办法:
先从远端pull一下,执行:git pull origin master //从master分支拉取
pull之后若还是同样的报错,可以用命令:(也可以直接用此命令,不经过上面的pull):
git push origin master -f
注意:
网上有说办法:
先用git pull --rebase origin master ,再push提交的,
但git pull --rebase origin master可能会把你本地库的所有修改覆盖成远程库的老版本,丢失文件,慎用!!
不过要真用了,丢失了文件,也可以用命令找回来:git rebase --abort