Git refusing to merge unrelated histories on rebase

后端 未结 23 2673
旧巷少年郎
旧巷少年郎 2020-11-22 08:30

During git rebase origin/development the following error message is shown from Git:

fatal: refusing to merge unrelated histories
Error redoing m         


        
23条回答
  •  忘了有多久
    2020-11-22 08:49

    I had the same problem. The problem is remote had something preventing this.

    I first created a local repository. I added a LICENSE and README.md file to my local and committed.

    Then I wanted a remote repository so I created one on GitHub. Here I made a mistake of checking "Initialize this repository with a README", which created a README.md in remote too.

    So now when I ran

    git push --set-upstream origin master
    

    I got:

    error: failed to push some refs to 'https://github.com/lokeshub/myTODs.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.
    

    Now to overcome this I did

    git pull origin master
    

    Which resulted in the below error:

    From https://github.com/lokeshub/myTODs
    branch            master     -> FETCH_HEAD
    fatal: refusing to merge unrelated histories**
    

    I tried:

    git pull origin master --allow-unrelated-histories
    

    Result:

    From https://github.com/lokeshub/myTODs
     * branch            master     -> FETCH_HEAD
    Auto-merging README.md
    CONFLICT (add/add): Merge conflict in README.md
    Automatic merge failed;
    fix conflicts and then commit the result.
    

    Solution:

    I removed the remote repository and created a new (I think only removing file README could have worked) and after that the below worked:

    git remote rm origin
    git remote add origin https://github.com/lokeshub/myTODOs.git
    git push --set-upstream origin master
    

提交回复
热议问题