git - 将本地文件中的更新推送到 github 存储库时出错
问题描述
我在本地对项目的一些 HTML 文件进行了一些更改,并尝试使用 Git Bash 将更改推送到我的 github 存储库中。但它显示以下错误
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
我已经从 Github 更改了存储库的名称,但随后使用命令在 Git Bash 上对其进行了更新
git remote set-url origin https://github.com/cyborg7459/bambinos-task1
如何解决这个问题?
解决方案
这里的问题是远程存储库正在更新其他用户的提交,而这些提交在您的本地不可用。因此,为了将本地更改推送到远程,您可以做的是首先将更改从上游拉到本地,解决合并冲突(如果有)并提交,然后最后推送。
从上游拉取/获取最新更改
git pull origin <branch>
推送更改
git push origin <branch>
注意 在某些情况下,拉取后可能会出现合并冲突,那么您必须在本地解决问题。暂存并提交更改。
git add .
git commit -m <commit message>
git push origin <branch>
推荐阅读
- python - Python 读取 100 多个 CSV 文件并将每个 CSV 文件中的列总和返回到新的 csv 中
- python - 访问 SQLite DB /w python 并获取格式错误的 DB
- javascript - 机器人找不到我的一个公会成员
- google-chrome - 断字连字符如何与复制粘贴一起使用(在 LaTeX / PDF 中)
- python - 如何在python字符串格式中仅添加不带括号的列表值
- selenium-webdriver - Appium c# windows显示异常:目前仅支持笔和触摸指针输入源类型
- c++ - Visual Studio 无法识别 boost::asio
- android - 增加选项卡布局中选项卡上的宽度自定义视图
- r - 将数据框加载到 R 中并使用 setDT
- javascript - 如何在 Chrome 扩展中使用 Google People API 来获取我的联系人姓名、电子邮件、电话号码和组织