1、报错信息:更新被拒绝,因为您当前分支的提示落后,See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
User@6-cpgh0065 MINGW64 /d/code (feature-notification-ghh|MERGING)
$ git push origin feature-notification-ghh
! [rejected] feature-notification-ghh -> feature-notification-ghh (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
错误:non-fast-forward
远程仓库:feature-notification-ghh
远程分支:feature-notification-ghh
本地分支:feature-notification-ghh
2、解决方法:
Git 已经提示我们,先用 git pull
把最新的内容从远程分支(origin/master
)拉下来,但是在 git pull
时,还有其他的错误:
$ git pull --rebase
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 38 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (38/38), 14.37 KiB | 55.00 KiB/s, done.
From code
bc32f26fc..8578b4ece feature-incidentscreen-guandian-new -> origin/feature-incidentscreen-guandian-new
There is no tracking information for the current branch.
Please specify which branch you want to rebase against.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> feature-notification-ghh
原因是没有指定本地 feature-notification-ghh
分支和远程 origin/feature-notification-ghh
的连接,这里根据提示需要执行:
git branch --set-upstream-to=origin/feature-notification-ghh feature-notification-ghh
3、完整的解决过程:
① 指定本地 feature-notification-ghh
分支和远程 origin/feature-notification-ghh
的连接:
git branch --set-upstream-to=origin/feature-notification-ghh feature-notification-ghh
② 拉取远程分支的代码并合并到本地分支:
# 方式1
git pull --reabse
# 方式2
git pull origin feature-notification-ghh
③ pull
还可能产生 conflict
,这里需要自己手动解决冲突再 merge
,解决冲突我们可以使用idea来解决
在idea中,找到version control–>local changes即可看到冲突的代码,点击resolve,选择accept yours还是选择accept theirs
④ 解决完冲突之后,查看状态并提交到远程仓库:
$ git status -s
User@6-cpgh0065 MINGW64 /d/code (feature-notification-ghh|MERGING)
$ git add ./
User@6-cpgh0065 MINGW64 /d/code (feature-notification-ghh|MERGING)
$ git commit -m ”处理冲突“
[feature-notification-ghh 41bb92bfc] ”处理冲突“
⑤ 将代码推送到远程:
User@6-cpgh0065 MINGW64 /d/code (feature-notification-ghh)
$ git push origin feature-notification-ghh
Enumerating objects: 97, done.
Counting objects: 100% (97/97), done.
Delta compression using up to 6 threads
Compressing objects: 100% (34/34), done.
Writing objects: 100% (42/42), 4.15 KiB | 303.00 KiB/s, done.
Total 42 (delta 24), reused 0 (delta 0), pack-reused 0
User@6-cpgh0065 MINGW64 /d/code/ngsoc/ngsoc (feature-notification-ghh)