問(wèn)題描述
本地修改代碼后正準(zhǔn)備push到遠(yuǎn)程倉(cāng)庫(kù),但是遇到了如下問(wèn)題:
error: failed to push some refs to 'https://github.com...'
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 pull
獲得
ou@ous-MacBook-Pro demo % git pull
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
這是因?yàn)樵趫?zhí)行 git pull 命令時(shí),Git 會(huì)自動(dòng)嘗試合并遠(yuǎn)程倉(cāng)庫(kù)的更改和本地倉(cāng)庫(kù)的更改,如果本地存在未提交的更改,可能會(huì)導(dǎo)致代碼沖突或其他問(wèn)題。輸入git pull --rebase origin master
無(wú)法解決問(wèn)題
ou@ous-MacBook-Pro demo % git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
解決方案
我選擇先保存未提交的更改,使用 git stash 命令將這些更改保存到一個(gè)棧中,以便稍后重新應(yīng)用這些更改。執(zhí)行以下命令:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-723514.html
# 先保存到一個(gè)棧
ou@ous-MacBook-Pro demo % git stash
Saved working directory and index state WIP on main: ...
# 合并遠(yuǎn)程倉(cāng)庫(kù)的更改和本地倉(cāng)庫(kù)的更改
ou@ous-MacBook-Pro demo % git pull
# 將更改恢復(fù)回來(lái)
ou@ous-MacBook-Pro demo % git stash pop
# 提交本地倉(cāng)庫(kù)更改
ou@ous-MacBook-Pro demo % git push
至此,問(wèn)題就解決了。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-723514.html
到了這里,關(guān)于解決error: failed to push some refs to ‘https://github.com...‘問(wèn)題的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!