"On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to ..."解决

来源:互联网 发布:机器人c语言编程实例 编辑:程序博客网 时间:2024/06/05 10:09

在git使用时,需要将本地修改的代码提交到远程库时,push时却出现以下错误

To ssh://git@localhost:*/user/project.git ! [rejected]        master -> master (fetch first)error: failed to push some refs to 'ssh://git@localhost:*/user/project.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

查看git status出现以下提示:

On branch masterYour branch is ahead of 'origin/master' by 2 commits.  (use "git push" to publish your local commits)nothing to commit, working directory clean

这是为什么呢?
原因是,在你关联本地库和远程库以后,两者的文件是一致的,之后,你修改了本地库的文件,同时远程库的文件也被你修改了。当两者都有修改的时候,由push方(这里是本地库)来先做远程库和本地库的合并之后,再提交本地库的修改到远程库。因此需要在commit和push之间,做pull操作,即按以下步骤提交修改:

git add *git commit -m 'change'git pullgit push origin master

输出的log中没有error或hint,提交成功啦~恭喜(ps:其实当出现错误时,输出的log中都已经告诉大家解决方案啦~)

阅读全文
0 0
原创粉丝点击