Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge reports "Already up-to-date" though there is a difference

Tags:

git

merge

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?

like image 623
Charles Darke Avatar asked Mar 11 '09 13:03

Charles Darke


People also ask

Why does git say my master branch is already up to date even though it is not?

If the current branch is not outdated compared to the one you pull from, pull will say Already up-to-date. even if you have local changes in your working directory. git pull is concerned with branches, not the working tree — it will comment on the working tree only if there are changes which interfere with the merge.

Will git merge overwrite my changes?

Usually git does not overwrite anything during merge.

How do you solve fatal refusing to merge unrelated histories?

The alternative (and longer) way of fixing the fatal: refusing to merge unrelated histories issues is to unstage your current commits, stash them, clone your required remote repository, and then place your stashed branch contents into the new clone.


1 Answers

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.

Your branch is up-to-date with respect to its parent. According to merge there are no new changes in the parent since the last merge. That does not mean the branches are the same, because you can have plenty of changes in your working branch and it sounds like you do.

Edit 10/12/2019:

Per Charles Drake in the comment to this answer, one solution to remediate the problem is:

git checkout master git reset --hard test 

This brings it back to the 'test' level.

Then do:

git push --force origin master 

in order to force changes back to the central repo.

like image 160
Bombe Avatar answered Sep 27 '22 19:09

Bombe