Git refusing to merge unrelated histories on rebase

后端 未结 23 2258
旧巷少年郎
旧巷少年郎 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:54

    I had the same problem. Try this:

    git pull origin master --allow-unrelated-histories 
    
    git push origin master
    
    0 讨论(0)
  • 2020-11-22 08:55

    I ran this command and issue got resolved.1

    git pull origin branchName --allow-unrelated-histories
    
    0 讨论(0)
  • 2020-11-22 08:56

    I tried git pull --allow-unrelated-histories didn't work, but what solves this issue for me was:

    1. I copied all the files on my desktop repository to another folder and then deleted the folder.

    2. Then I clone the repo again because it is a new project.

    3. When I copied my files again and push it worked like charm.

    0 讨论(0)
  • 2020-11-22 08:58

    This usually happens when you commit first time to remote repository. As error clearly says "refusing to merge unrelated histories", we need to use --allow-unrelated-histories flag.

    git pull origin master  --allow-unrelated-histories
    

    Now there would be some conflicts which we have to solve manually. After that just commit the code and push it.

    0 讨论(0)
  • 2020-11-22 08:58

    I see the most voted answer doesn't solve this question, which is in the context of rebasing.

    The only way to synchronize the two diverged branches is to merge them back together, resulting in an extra merge commit and two sets of commits that contain the same changes (the original ones, and the ones from your rebased branch). Needless to say, this is a very confusing situation.

    So, before you run git rebase, always ask yourself, “Is anyone else looking at this branch?” If the answer is yes, take your hands off the keyboard and start thinking about a non-destructive way to make your changes (e.g., the git revert command). Otherwise, you’re safe to re-write history as much as you like.

    Reference: https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing

    0 讨论(0)
  • 2020-11-22 09:01

    When doing a git pull, I got this message fatal: refusing to merge unrelated histories for a repo module where I hadn't updated the local copy for a while.

    I ran this command just to refresh local from origin. I just wanted latest from remote and didn't need any local changes.

    git reset --hard origin/master
    

    This fixed it in my case.

    0 讨论(0)
提交回复
热议问题