日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Git错误non-fast-forward后的冲突解决

發布時間:2025/3/15 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Git错误non-fast-forward后的冲突解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

當要push代碼到git時,出現提示:

error:failed to push some refs to ...

Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:

  • $?git?push?origin?master??

  • To?../remote/??

  • ?!?[rejected]????????master?->?master?(non-fast?forward)??

  • error:?failed?to?push?some?refs?to?'../remote/'??

  • To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again. ?See the 'non-fast forward'
    section of 'git push --help' for details.
    This error can be a bit overwhelming 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.
    In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is 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.


    問題(Non-fast-forward)的出現原因在于:git倉庫中已經有一部分代碼,所以它不允許你直接把你的代碼覆蓋上去。于是你有2個選擇方式:

    1,強推,即利用強覆蓋方式用你本地的代碼替代git倉庫內的內容

    git push -f

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

    $ git fetch

    $ git merge

    這2句命令等價于

  • $?git?pull??

  • 可是,這時候又出現了如下的問題:


    上面出現的 [branch "master"]是需要明確(.git/config)如下的內容
    [branch "master"]
    ? ? remote = origin

    ? ? 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上輸入如下命令行:

  • $?git?config?branch.master.remote?origin??

  • $?git?config?branch.master.merge?refs/heads/master??

  • 之后再重新git pull下。最后git push你的代碼吧。it works now~


    轉載于:https://my.oschina.net/liangzhenghui/blog/505861

    總結

    以上是生活随笔為你收集整理的Git错误non-fast-forward后的冲突解决的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。