[置顶] "On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to ..."解决
2017-11-01 19:21
429 查看
在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 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出现以下提示:
On branch master Your 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 pull git push origin master
输出的log中没有error或hint,提交成功啦~恭喜(ps:其实当出现错误时,输出的log中都已经告诉大家解决方案啦~)
相关文章推荐
- Git Your branch is ahead of 'origin/master' by X commits解决方法
- git出错"Your branch is ahead of 'origin/LS3A_2H' by 4 commits"解决
- git status message - Your branch is ahead of origin/master by X commits
- Your branch is ahead of 'origin/master' by 2 commits.
- Your branch is ahead of 'origin/master' by 1 commit
- Your branch is ahead of 'origin/master' by 1 commit
- Your branch is ahead of 'origin/master' by 1 commit
- Your branch is ahead of 'origin/master' by 1 commit
- git Your branch is ahead of 'origin/master'
- 解决git中upstream丢失问题Your branch is based on 'origin/xxxx', but the upstream is gone.
- git push 报错"Updates were rejected because the tip of your current branch is behind"
- why does it say “Your branch is ahead of origin/master
- 【已解决】github中git push origin master出错:error: failed to push some refs to
- 【已解决】github中git push origin master出错:error: failed to push some refs to
- VMware安装Ubuntu17.04的VMware-tools提示:what is the location of the "ifconfig" program on your machin问题解决
- [Linux] Git: push 出错的解决 master -> master (branch is currently checked out)
- [Linux] Git: push 出错的解决 master -> master (branch is currently checked out)
- Git上传项目提示Push rejected: Push to origin/master was rejected解决办法
- Git: push 出错的解决 master -> master (branch is currently checked out)
- git push origin master 报错 remote rejected] master -> master (branch is currently checked out)