剛開始學(xué)習(xí)使用git,通過push命令:打算將本地倉庫中的文件上傳到遠端倉庫時,報了以下錯誤:
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.
原因:遠程倉庫不為空:自己在創(chuàng)建遠程倉庫的時候,添加了如下兩個文件,本地倉庫中并沒有這兩個文件。
解決方法:添加:–allow-unrelated-histories
git pull origin master --allow-unrelated-histories
將遠端的本地文件首先拉取到本地來,因為commit的時間不一致,所以直接拉去的時候就會出現(xiàn)問題,必須添加忽略不相干的歷史選項,這樣本地文件中也出現(xiàn)了read.md和readen.md兩個文件了。
之后再正常推送即可。
git push origin master
引用:
首先它的出現(xiàn)是因為在你上傳的時候,遠程倉庫中有著本地倉庫沒有的文件,及導(dǎo)致本地倉庫和遠程有不同的開始點,也就是兩個倉庫沒有共同的 commit 出現(xiàn)的無法提交。文章來源:http://www.zghlxwxcb.cn/news/detail-509929.html
以后還是先創(chuàng)建遠端倉庫,然后clone到本地吧,不會出現(xiàn)什么問題;或者遠端倉庫默認不要添加初始化文件,設(shè)置為空即可。
本質(zhì)上是將分支進行了合并。文章來源地址http://www.zghlxwxcb.cn/news/detail-509929.html
到了這里,關(guān)于git 報錯:Updates were rejected because the remote contains work that you do問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!