Home > OS >  Git , Merge Already Up TO date but with diff?
Git , Merge Already Up TO date but with diff?

Time:10-13

I have two local branches, say A and B. I run the following commands

  1. git checkout A
  2. git merge -X theirs B - "comment"

if i run again the command
git merge B --> it throws the message "Already up to date"

if i run the follow command git diff A..B --> it returns differences in 4 files

So I "smash" the content of branch A with the content of branch B if i run again the merge command on branch A it returns that everything is up to date but if i run the "diff" between the two branches it return differences in four files.

What is happening ?

Thanks in advance.
Best regards

CodePudding user response:

Things to know:

  • Git traffics in commits.

  • Every commit has at least one parent, and "reaches" other commits by means of its chain of parents.

  • A branch is a name for one commit.

  • Merging creates a commit and moves the branch name of the current branch.

  • The phrase "up to date" means that one branch doesn't reach any commits that the other branch doesn't reach.

So let's say we start with this situation (arrow point backwards in time, each commit pointing at its parent):

A <-- B <-- C <-- D (branch1)
 ↖︎
   <-- X <-- Y <-- Z (branch2)

Now I checkout branch1 and say git merge branch2. I get this:

A <-- B <-- C <-- D <-- M (branch1)
 ↖︎                    ↙︎
   <-- X <-- Y <-- Z (branch2)

So now, on the one hand, there is no point trying to merge branch2 into branch1 again; branch1 already reaches all the same commits that branch2 reaches. Hence, "up to date". But commit M and commit Z are not identical to one another either.


Perhaps your confusion is because you think

git merge -X theirs B

does something special with regard to a merge. It doesn't. This is still a perfectly ordinary merge. The only thing it does specially is in case there happen to be any merge conflicts; the theirs provides a hint about how to resolve those conflicts without asking for human help.

  • Related