Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There isn't anything to compare. Nothing to compare, branches are entirely different commit histories

People also ask

Are entirely different commit histories GitHub?

The Short Answer It looks like GitHub won't let you compare the branches because they don't actually share any of the same history at all, even though they may share much of the same files and code. It says: There isn't anything to compare. master and upstreambranch are entirely different commit histories.

Can we compare two branches in GitHub?

To compare branches, you can select a branch name from the compare drop down menu at the top of the page. Here's an example of a comparison between two branches.

How do I merge branches with different history?

To combine two separate Git repositories into one, add the repository to merge in as a remote to the repository to merge into. Then, combine their histories by merging while using the --allow-unrelated-histories command line option.

What is -- allow unrelated histories?

Option 1: Use '–allow-unrelated-histories' You can also replace the master branch with whatever branch you want the pull request to merge into. The idea behind --allow-unrelated-histories is that git lets you merge unrelated branches. This git flag works seamlessly when there are no file conflicts.


The Short Answer

It looks like GitHub won't let you compare the branches because they don't actually share any of the same history at all, even though they may share much of the same files and code.

Here is a screenshot of the temporary fork I made of your repo, where I tried to compare master with the upstreambranch, like you described. Notice the error message:

Error message screenshot

It says:

There isn't anything to compare.

master and upstreambranch are entirely different commit histories.

The Long Answer

You probably downloaded the original source and added it to a completely new repo instead of cloning the original repo, right? Doing that will make it so that the history of your repo will be completely different from the history of the original repo, since your new repo won't have any of the same commits with the same sha IDs.

You can see that by doing a reverse log of your master branch and the upstreambranch:

# Your first commit, see commit sha
git log --reverse master
commit c548d7b1b16b0350d7fbdb3ff1cfedcb38051397 # <== HERE
Author: Padraic Stack <[email protected]>
Date:   Wed Apr 2 15:11:28 2014 +0100

    First commit of everything

# First commit sha of the original repo
git log --reverse upstreambranch
commit 105a12817234033c45b4dc7522ff3103f473a862 # <== THERE
Author: Jeremy Boggs <[email protected]>
Date:   Mon Feb 22 16:00:53 2010 +0000

    Creates repo directories for the Seasons theme.

Solutions

If you redo your commits on top of the original history, you should then be able to compare the branches. There are several different ways that you can redo your commits, including

git rebase --onto

and

git cherry-pick

You also can redo each commit manually, if you have to.


I solve my issue using these commands

git checkout [BRANCH]   
git branch master [BRANCH] -f   
git checkout master   
git push origin master -f

I had a similar situation, where my master branch and the develop branch I was trying to merge had different commit histories. None of the above solutions worked for me. What did the trick was:

Starting from master:

git branch new_branch
git checkout new_branch
git merge develop --allow-unrelated-histories

Now in the new_branch, there are all the things from develop and I can easily merge into master, or create a pull request, as they now share the same commit hisotry.


If the problem is "main and master are entirely different commit histories.", the following will work

git checkout master   
git branch main master -f    
git checkout main  
git push origin main -f 

You can force update your master branch as follows:

git checkout upstreambranch  
git branch master upstreambranch -f    
git checkout master  
git push origin master -f

For the ones who have problem to merge into main branch (Which is the new default one in Github) you can use the following:

git checkout master  
git branch main master -f    
git checkout main  
git push origin main -f

The following command will force both branches to have the same history:

git branch [Branch1] [Branch2] -f 

From the experiment branch

git rebase master
git push -f origin <experiment-branch>

This creates a common commit history to be able to compare both branches.