git push 报错 error: failed to push some refs to 解决记录

D:\csdn\csdnhb-ui>git push origin master:moshangshang
To githy.csdn.com:pdd-fe/csdnhb-ui.git
! [rejected] master -> moshangshang(non-fast-forward)
error: failed to push some refs to '[email protected]:pdd-fe/csdnhb-ui.g
it'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.

D:\csdn\csdnhb-ui>

这里表示本地版本落后于远程版本,远程版本有人做过修改并且已经提交,所以现在本地提交会报错behind its remote。因此先拉远程的master版本过来,之后再在远程的版本之上修改
D:\csdn\csdnhb-ui>git pull origin master
error: Pulling is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

D:\csdn\csdnhb-ui>

解决方法: 
1.pull代码的时候会进行git merge操作导致冲突,需要将冲突的文件先resolve掉,再进行git add -u, git commit之后才能成功git pull。 
2.如果想放弃本地的文件修改,可以使用git reset --hard FETCH_HEAD,FETCH_HEAD表示上一次成功时git pull之后形成的commit点。后面就可以成功git pull. 
ps:git merge会形成MERGE-HEAD(FETCH-HEAD) 。git push会形成HEAD这样的引用。HEAD代表本地最近成功push后形成的引用。

D:\csdn\csdnhb-ui>git branch
moshangshang
* master

D:\csdn\csdnhb-ui>git add .

D:\csdn\csdnhb-ui>git status
On branch master
Your branch is up-to-date with 'origin/master'.

You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: src/view/onlineOperate/createTable.vue


D:\csdn\csdnhb-ui>git commit -m "lbz1"
[master abd5a39] lbz1
1 file changed, 3 insertions(+), 3 deletions(-)

D:\csdn\csdnhb-ui>git push origin master:moshangshang
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 496 bytes | 496.00 KiB/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote:
remote: To create a merge request for moshangshang, visit:
remote: http://githy.csdn.com/pdd-fe/csdnhb-ui/merge_requests/new?merge_re
quest%5Bsource_branch%5D=moshangshang
remote:
To githy.csdn.com:pdd-fe/csdnhb-ui.git
6b3caeb..abd5a39 master -> moshangshang
D:\csdn\csdnhb-ui>

参考文章地址:https://blog.csdn.net/u011957758/article/details/50901122

猜你喜欢

转载自blog.csdn.net/mchdba/article/details/83720770
今日推荐