最近使用git 推送代码到远程碰到的问题 使用git init初始化项目后使用下方的代码推送
git add
git commit -m "some message"
git push origin master
之后报错
rror: failed to push some refs to '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禁止本次推送(看网上是这么说的)
解决方案
$ git push origin master --force
使用git -f 强制推送(不推荐)会覆盖之前的推送记录 容易挨骂
$ git pull origin master --allow-unrelated-histories
拉取远程的代码这样你的本地就有了远程分支的代码 但是这样可能会导致本地的代码被master覆盖掉,本地最好有备份