copy from :https://blog.csdn.net/k_young1997/article/details/90489734
今天將項目修改了一部分,然后用 git push origin master 向遠程倉庫推送的時候報如下錯誤:
error: failed to push some refs to 'https://github.com/ZJyoung1997/JZShop.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.
1
2
3
4
5
6
原因是遠程倉庫中的文件和我們本地的倉庫有差異,例如你的遠程倉庫有個文件Readme. md,但是本地倉庫卻沒有,就可能會出現這種情況。 我的就是遠程倉庫中有Readme. md文件,而本地倉庫中沒有該文件造成的。還有就是因為平時在協會中,用協會電腦開發,回到寢室后又會用自己的電腦開發,這可能也是導致這種問題的原因。這種情況有解決辦法,就是將本地倉庫直接干掉,然后重新從遠程clone一個,但是這樣顯然太麻煩了,可以用合並分支的方法
解決辦法:
git pull --rebase origin master
1
git pull命令用於從另一個存儲庫或本地分支獲取並集成(整合),取回遠程主機某個分支的更新,再與本地的指定分支合並。
如果報如下錯誤,也可以用 git pull 命令
fatal: 'master' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
1
2
3
4
5
6
用 git pull origin master --allow-unrelated-histories 解決
————————————————
版權聲明:本文為CSDN博主「Been_You」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/k_young1997/article/details/90489734