I'm using Git as the version control for a Django/ Python project for which I recently took over the development, having not used it much previously.
Recently, I created a new branch from the master
branch, in order to work on fixing a bug (obviously, doing the development on my local machine, with the intention of pushing to the server once I had fixed the bug).
The branch on which I have been doing the development work is called dateReceived
, and I recently fixed the particular bug that I had created this branch to work on.
After completing the work, I tried to merge dateReceived
back with my local master
, but there were a number of conflicts which seemed to break my local master
branch, and I was unable to resolve them, so the version on my local master
was then no longer working.
I restored my local master
to a backup I had made from the live version on the server by checking out a commit
that I had made prior to starting work on this bug, when everything else was still working. This meant that I was briefly in a 'detached head' state, before I committed/ branched again, and started working from there. I was then no longer in a 'detached head' state.
So, on the live server, I now have the original master
branch, which is working correctly- except for the bug that I am working on locally, and on my development machine, I have two branches: master
, which is up-to-date with the version on the live server (and on which the bug still exists), and dateReceived
, which is working correctly (with the bug fixed).
If I checkout my local master
branch, and view the site in my browser from localhost:800/.../.../concept
, I can see that the bug still exists when I try to perform that particular function on that page of the website.
But, if I checkout my local dateReceived
branch, and view the site in my browser from localhost:8000/.../.../concept
, I can see that the bug has been fixed when I try to perform that particular function on that page of the website.
If I try merging dateReceived
into master
again now on my local machine (ready to push my local master
branch to the server once it is up to date with the bug fixed) using the command:
git merge dateReceived
from my master
branch, I get a message that says:
Already up-to-date
but it clearly isn't, since the bug still exists in master
, but is fixed in dateReceived
.
If I run:
git diff dateReceived
from my master
branch, a list of the differences between master
and dateReceived
are shown- so clearly, Git can tell that there are differences between the two branches...
I found a similar question at: Git merge reports "Already up-to-date" though there is a difference
and the accepted answer seems to suggest that the branch I am trying to merge is a parent of my current branch, which I guess may have happened when I restored a commit after breaking my local master
.
It seems that the way to resolve this is to do a hard reset
, but I am quite wary of doing this, since as I understand, it will completely remove changes, etc with no way of reverting after I do it...
Is this actually the only way to resolve the issue that I'm having with master
saying it's already up-to-date when trying to merge another branch into it, even though I can actually see that it's not, or is there anything else I can do?
What are the potential risks of doing a hard reset
, and how can I minimise those risks? Is there anything else I can do to resolve this git merge
issue, so that I can merge dateReceived
into master
in order to push the fixed version to the server?
I believe that either this is true, or something else happened to your local
master
branch to put in a bad state. Regardless of what is wrong, you should be safe resetting it to the version which is on the remote, which seems to be working properly (minus the one bug). Try the following:And then try doing the merge again:
If you get merge conflicts, don't panic, but rather examine each conflicted file in your IDE if possible, or even in any text editor. My guess is that you will be able to get through them. Then, make the merge commit and hopefully your bug should be resolved.