Git   发布时间:2019-10-25  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了git错误non-fast-forward后的冲突解决大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

来自:https://www.linuxidc.com/Linux/2012-04/58985.htm 侵删

当要push代码到git时,出现提示:

error:failed to push some refs to ...

Dealing with “non-fast-forWARD” errors

  • To ../remote/  
  •  master (non-fast forWARD)  
  • error: failed to push some refs to '../remote/'  
  • To prevent you from losing history,non-fast-forWARD updates were rejected
    WARD'
    Help' for details.
    HelR_907_11845@ing at first,do not fear. Simply put,git cAnnot make the change on the remote without losing commits,so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch,or using pull to perform both at once.
    what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch,and is considered bad practice. When in doubt,don’t force-push.

    title="git错误non-fast-forWARD后的冲突解决" alt="git错误non-fast-forWARD后的冲突解决" src="https://cn.js-code.com/res/2019/02-27/20/a1abf01bee2213fe5d1d1866a7bdd250.png" >

    问题(Non-fast-forWARD)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

    1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容

    git push -f

    2,先把git的东西fetch到你本地然后merge后再push

    $ git fetch

    $ git merge

    这2句命令等价于

  • 可是,这时候又出现了如下的问题:

    title="git错误non-fast-forWARD后的冲突解决" alt="git错误non-fast-forWARD后的冲突解决" src="https://cn.js-code.com/res/2019/02-27/20/d16af47f4b47f2008c4fbf7062e0a215.png" >

    上面出现的 [branch "master"]是需要明确(.git/config)如下的内容

        merge = refs/heads/master

    这等于告诉git2件事:

    1,当你处于master branch,默认的remote就是origin。

    2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

    如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

    1. $ git config branch.master.merge refs/heads/master  

    大佬总结

    以上是大佬教程为你收集整理的git错误non-fast-forward后的冲突解决全部内容,希望文章能够帮你解决git错误non-fast-forward后的冲突解决所遇到的程序开发问题。

    如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

    本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
    如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
    标签: