tags:

views:

983

answers:

2
+3  Q: 

Git merge mystery

I have a git repository with 2 branches: master and test.

There are differences between master and test branches.

Both branches have all changes committed.

If I do:

git checkout master
git diff test

A screen full of changes appears showing the differences. I want to merge the changes in the test branch and so do:

git merge test

But get the message "Already up-to-date"

However, examining files under each different branch clearly shows differences.

What's the problem here and how do I resolve it?

+3  A: 

The message “Already up-to-date” means that all the changes from the branch you’re trying to merge have already been merged to the branch you’re currently on. More specifically it means that the branch you’re trying to merge is a parent of your current branch. Congratulations, that’s the easiest merge you’ll ever do. :)

Use gitk to take a look at your repository. The label for the “test” branch should be somewhere below your “master” branch label.

Bombe
Holy cr*p! You're right! I think what happened was that another branch (unstable development) was incorrectly merged with master and the test branch was a sub-set of unstable.The merge I was trying to make was to bring master back to the 'test' level.
Charles Darke
Right. That operation wouldn’t make any sense so Git refuses to do anything. :)
Bombe
What I've done now is: git checkout master; git reset --hard test;This brings it back to the 'test' level. I then did a "git push --force origin master" to force changes back to the central repo.
Charles Darke
Would have been nice if git had a warning to say "trying to merge with parent".
Charles Darke
Pushing a branch that is not a descendant of the branch already existing on the remote side is considered a bad thing: See the discussions on the man pages for git-push and git-pull.
Bombe
Yeah. Unpicking the whole thing would have taken too long, so I just backed up the repo, did the force push and checked result was what I wanted.
Charles Darke
A: 

A merge is always between the current HEAD and one or more commits (usually, branch head or tag),
and the index file must match the tree of HEAD commit (i.e. the contents of the last commit) when it starts out.
In other words, git diff --cached HEAD must report no changes.

The merged commit is already contained in HEAD. This is the simplest case, called "Already up-to-date."

That should mean the commits in test are already merged in master, but since other commits are done on master, git diff test would still give some differences.

VonC