2

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?

1 Answer 1

1

the accepted answer seems to suggest that the branch I am trying to merge is a parent of my current branch

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:

git fetch origin                 # update origin/master to the remote
git checkout master              # switch to local master branch
git reset --hard origin/master   # reset local master to origin/master

And then try doing the merge again:

git merge dateReceived

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.

20
  • Thanks for your answer- I'll do what you've suggested in a moment, but before I do, I just want to check: after performing these steps, and doing the git reset --hard origin/master, will I lose any of my previous commits/ other branches, or will all of my commit history and other branches still be there ready to be used again in future if I decide I need to? Apologies if this seems pretty basic- it's just that I am quite new to Git, and still a bit unsure of how it works... Commented Jan 5, 2017 at 10:15
  • All good questions: The reset operation will reset your local master branch to whatever is on the remote. If you have some local commits which you have not yet pushed to the remote, then you should not use this method. If so, I can give you a way to find the commit locally to which to reset. Commented Jan 5, 2017 at 10:16
  • The setup I am working with is: on the live server, I have one branch- master, which is currently in a working state, and my colleagues are using this to manage their work projects every day (which is why I need to be absolutely sure any changes I push to the live server are working and won't break anything else that is currently working). On my local machine, I have several branches- master, which should in theory always be the same as the master branch on the server, and then have a number of other branches which were created from master, with git branch newBranch, which I have Commented Jan 5, 2017 at 10:28
  • created for every new feature that I have added, and every bug that I have tried to fix. When I am happy that the new feature works, or the bug has been fixed, I then merge the newBranch that was created for the development of the new feature/ bug into my local master, check that the new feature/ bug resolution works on my localhost (while on master), and then push my local master to the server. Commented Jan 5, 2017 at 10:31
  • Unfortunately your comments don't help us find a solution. We need to know whether your current remote master branch is acceptable. Please answer this question. Commented Jan 5, 2017 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.