一.问题描述

本地仓库push到远程报错:

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master)
$ git push origin master
To github.com:fanyu-aprivot/SeleniumPython.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:fanyu-aprivot/SeleniumPython.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.

二.问题解决

网上查了下是因为远程库与本地库不一致,对我的仓库而言指的是远程库多了一个READ.me文件

1.先把远程库和本地库合并

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master)
$ git pull origin master
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 1.34 KiB | 42.00 KiB/s, done.
From github.com:fanyu-aprivot/SeleniumPython
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories

报错是因为这是两个不同的历史提交

可以使用强制合并

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master)
$ git pull origin master --allow-unrelated-histories
From github.com:fanyu-aprivot/SeleniumPython
 * branch            master     -> FETCH_HEAD
CONFLICT (add/add): Merge conflict in README.md
Auto-merging README.md
Automatic merge failed; fix conflicts and then commit the result.

查看本地文件:

在这里插入图片描述
2.再次推送

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master|MERGING)
$ git add .

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master|MERGING)
$ git status
On branch master
All conflicts fixed but you are still merging.
  (use "git commit" to conclude merge)

Changes to be committed:
        modified:   README.md


darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master|MERGING)
$ git commit -m "本地selenium python代码提交到远程"
[master d8db24c] 本地selenium python代码提交到远程

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master)
$ git remote -v
origin  git@github.com:fanyu-aprivot/SeleniumPython.git (fetch)
origin  git@github.com:fanyu-aprivot/SeleniumPython.git (push)

darli@LAPTOP-LMMPH4VI MINGW64 /d/D1/code/AutoTest/python_ui_autotest/SeleniumPython (master)
$ git push origin master
Enumerating objects: 192, done.
Counting objects: 100% (192/192), done.
Delta compression using up to 12 threads
Compressing objects: 100% (181/181), done.
Writing objects: 100% (190/190), 1.09 MiB | 2.07 MiB/s, done.
Total 190 (delta 44), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (44/44), done.
To github.com:fanyu-aprivot/SeleniumPython.git
   823994b..d8db24c  master -> master

3.查看远程库如期更新
在这里插入图片描述

参考文章:
https://blog.csdn.net/winnershili/article/details/78888548
https://blog.csdn.net/rocling/article/details/82956402
https://blog.csdn.net/uotail/article/details/80211897

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐