【杂谈】关于学习使用git提交本站代码心得


一、问题背景

在本次博客的建设中,我使用 GitHub Pages 完成这个项目,并且直接在 GitHub 库中存储数据。

二、报错详情

但是在推送时却失败了:

1
2
3
4
5
error: failed to push some refs to 'https://github.com/RivYayoi/RivYayoi.github.io.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. If you want to integrate the remote changes, use 'git pull'
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

三、初尝试:强制推送

进行拉取依然无效,我只能进行强制推送:

1
git push -f origin main

四、标准解决方案:Rebase 同步

后来我了解到需要使用 rebase 同步远程改动:

1
2
git pull --rebase origin main
git rebase --continue

五、日常推送流程

在多次拉取和推送之后终于恢复正常,日常操作如下:

1
2
3
4
git push -u origin main
git add .
git commit -m "safe"
git push origin main

六、总结

本次我对于 git 的理解从零到一,更上一层。


文章作者: 上江 Yayoi
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 上江 Yayoi !
  目录