当前位置: 首页 > 工具软件 > Patch-Master > 使用案例 >

Git Push时报错: ! [rejected] master -> master (non-fast-forward)

徐淳
2023-12-01

项目结构变更或过多文件增加但未commit再次提交git时经常会出现这个问题,为了加深自己印象记录下解决方案

$ git push origin master
To https://github.com/YuYanQing5920/UiAutomationFramework.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/YuYanQing5920/UiAutomationFramework.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.

结合其它博文讲述的方法、先pull保持本地与远程仓库一致性后提交、依然还是会报错

$ git pull --rebase origin master
$ git push origin master 
To https://github.com/YuYanQing5920/UiAutomationFramework.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/YuYanQing5920/UiAutomationFramework.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.

最后处理方案:

第一步:先执行git status 看出是否有文件未提交上传导致了与远程仓库不太一致的问题、若有问题则commit下

$ git status   
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .idea/UiAutomationFramework.iml
        .idea/inspectionProfiles/
        .idea/misc.xml
        .idea/modules.xml
        .idea/workspace.xml
        ATestClass/TestMain.py
        Common/Appium.py
        Common/Insert_DB.py
        Common/MysqlManager.py
        Common/UpdateJar.py
        Config/db.conf
        Emoji.md
        KeyCode.md
        README-CN.md
        Result/
        TestCase/
        Utils/

​$ git add .
$ git commit -m "XXXX"

第二步:执行git pull --rebase origin master 再次与远程仓库匹配

MrYu@LAPTOP-DGT7652I MINGW64 /d/Work_Spaces/PyCharm_Project/UiAutomationFramework (master)
$ git pull --rebase origin master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/YuYanQing5920/UiAutomationFramework
 * branch            master     -> FETCH_HEAD
   d315372..d2a0210  master     -> origin/master
First, rewinding head to replay your work on top of it...
Applying: :art:Add dbutils and appuim public classes
.git/rebase-apply/patch:1524: trailing whitespace.
| :suspect: `:suspect:` | :trollface: `:trollface:` |
.git/rebase-apply/patch:2090: trailing whitespace.
| :suspect: `:suspect:` | :trollface: `:trollface:` |
.git/rebase-apply/patch:2565: trailing whitespace.
2020-09-08 23:32:18,652 - Adb_Tools.py [line:59] - INFO:
.git/rebase-apply/patch:2570: trailing whitespace.
2020-09-08 23:32:18,677 - Adb_Tools.py [line:59] - INFO:
.git/rebase-apply/patch:2580: trailing whitespace.
2020-09-08 23:32:18,730 - Adb_Tools.py [line:59] - INFO:
warning: squelched 932 whitespace errors
warning: 937 lines add whitespace errors.
Using index info to reconstruct a base tree...
A       Until/Adb.py
Falling back to patching base and 3-way merge...
Removing README.md

第三步:git push origin master上传提交成功

$ git push origin master
Enumerating objects: 75, done.
Counting objects: 100% (75/75), done.
Delta compression using up to 8 threads
Compressing objects: 100% (52/52), done.
Writing objects: 100% (61/61), 68.07 KiB | 2.27 MiB/s, done.
Total 61 (delta 14), reused 0 (delta 0)
remote: Resolving deltas: 100% (14/14), completed with 7 local objects.
To https://github.com/YuYanQing5920/UiAutomationFramework.git
   d2a0210..4ced395  master -> master

 

 类似资料: