Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After I merge two branches, the `diff` command shows me that the two branches are still different

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading