I am working on two branches and now I want to merge them.
So I did this:
git checkout MainBranch
git merge SubBranch
That command runs fine.
But now, if I do this:
diff MainBranch SubBranch
it shows me differences in the code between the 2 branches.
Shouldn’t the merge make them the same?
>Solution :
Shouldn’t the merge make them the same?
No. After a true merge, one branch (the one that was merged) is one commit behind the other — because the merge commit is on one branch only (the one that was merged into). If you have this:
x --- y --- z (main)
\
a --- b (branch)
Then if you are on main and you merge branch, you have this:
x --- y --- z --- m (main)
\ /
a --- b (branch)
A merge commit (m) was added to main, but nothing about branch was changed.
Under some circumstances, Git may do a "fast-forward" when you ask to merge (or pull), in which case the two branches become momentarily identical. But a fast-forward is not a true merge.