git 提交 commit时,报错: Your branch is ahead of 'origin/master' by 2 commits.
Your branch is ahead of 'origin/master' by 2 commits.
原因:在之前已经有2个commit而没有push到远程分支上
解决方法:
(1)先git push origin **将本地分支提到远程仓库;
(2)或者直接git reset --hard HEAD~x解决,x表示的就是在这之前已经有多少次的提交,这句命令的意思就是直接回退到x 个commit之前(这两次提交所改动的代码都没有了,慎用)
另可执行:
git reset HEAD^ --soft --soft 表示保留当前commit,重新commit
git reset HEAD^ --hard --hard 表示丢弃当前add,重新add、commit
gitee push b报错
To https://gitee.com/sprite-ll/java-pro.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/sprite-ll/java-pro.git'
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.
原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
1、强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容,如果远程仓库是刚建的,没有代码,可以这样操作,尽量避免这种操作方法。
git push -f
1
2、先把git的东西fetch到你本地然后merge后再push
$ git fetch
1
$ git merge
1
3、在使用的时候,git merge,又出现了以下的问题
xu:QProj xiaokai$ git merge
fatal: refusing to merge unrelated histories
对于这个问题。使用git pull origin master --allow-unrelated-histories
来处理一下。
4、然后继续git merge,依然有问题
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
这个就好处理了,是我们没有提交当前的变化, git add .,git commit -am "提交信息"
然后再来一次git merge,然后ok.
5、然后输入git pull,显示如下
Already up-to-date.
1
2
最后就可以执行xu:QProj xiaokai$ git push origin master
将代码上传到公司的远程仓库中。
xu:QProj xiaokai$ git push origin master
Counting objects: 693, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (636/636), done.
Writing objects: 100% (693/693), 2.83 MiB | 570.00 KiB/s, done.
Total 693 (delta 362), reused 0 (delta 0)
remote: Resolving deltas: 100% (362/362), completed with 1 local object.
remote: Powered by Gitee.com
To https://gitee.com/XXXXX.git
83902a5..8100890 master -> master
1
上传完成。