解决error: failed to push some refs to 'xxxx'

桃扇骨 2022-01-28 10:23 248阅读 0赞

今天将项目修改了一部分,然后用 git push origin master 向远程仓库推送的时候报如下错误:

  1. error: failed to push some refs to 'https://github.com/ZJyoung1997/JZShop.git'
  2. hint: Updates were rejected because the remote contains work that you do
  3. hint: not have locally. This is usually caused by another repository pushing
  4. hint: to the same ref. You may want to first integrate the remote changes
  5. hint: (e.g., 'git pull ...') before pushing again.
  6. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

原因是远程仓库中的文件和我们本地的仓库有差异,例如你的远程仓库有个文件Readme. md,但是本地仓库却没有,就可能会出现这种情况。 我的就是远程仓库中有Readme. md文件,而本地仓库中没有该文件造成的。还有就是因为平时在协会中,用协会电脑开发,回到寝室后又会用自己的电脑开发,这可能也是导致这种问题的原因。这种情况有解决办法,就是将本地仓库直接干掉,然后重新从远程clone一个,但是这样显然太麻烦了,可以用合并分支的方法

解决办法:
  1. git pull --rebase origin master

git pull命令用于从另一个存储库或本地分支获取并集成(整合),取回远程主机某个分支的更新,再与本地的指定分支合并。

如果报如下错误,也可以用 git pull 命令

  1. fatal: 'master' does not appear to be a git repository
  2. fatal: Could not read from remote repository.
  3. Please make sure you have the correct access rights
  4. and the repository exists.

git pull origin master --allow-unrelated-histories 解决

发表评论

表情:
评论列表 (有 0 条评论,248人围观)

还没有评论,来说两句吧...

相关阅读