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?
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.
Usually git does not overwrite anything during merge.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With