1

Recently, trying to learn some branch merging I ended up screwing my master branch. My master branch code now contains that merge conflicts messages like: ">>>>>>HEAD ==========" all over it. When I try to merge it with the actual code without these messages (I do have a clean code in another branch), git says everything is up-to-date and there's nothing to be changed. Whenever I pull from my repo, the code contains these trash lines.

How should I solve it? Thanks in advance...

Lucas Lima
  • 41
  • 4
  • Fix the trash lines, commit and push to the remote – Martin G Jul 27 '16 at 13:23
  • Fixing the trash lines would result the clean code. Just commit the clean one and push it should do the trick then? – Lucas Lima Jul 27 '16 at 13:30
  • You can reset your master branch to non trash code and then merge that branch again and this time commit after you fix the conflict. http://stackoverflow.com/questions/4114095/how-to-revert-git-repository-to-a-previous-commit – sunitj Jul 27 '16 at 13:31
  • Managed to solve it... just like you guys said... just edited everything and commited again. Thank you all :) – Lucas Lima Jul 27 '16 at 20:02

2 Answers2

1

First things first... When you have this kind of "trash code" you have a conflict in your branch. This is caused by a change made before you on the same line... To fix this, you must resolve all the conflicts manually. Those lines says what is in your branch "HEAD" and what is in your master branch for example "MASTER".

>>>>>>HEAD 
Your code
==========
==========
Some change on the same line
<<<<<<Master

If this code remains on your file and no change is reported by git status command, you have already pushed this file with conflicts to your branch...

Just remove those lines and commit and push again...

Maybe you will need to look at file history to see what is the correct code to push.

Leandro
  • 1,114
  • 1
  • 12
  • 15
0

I assume you are working purely locally and did not push your changes to some remote.

Find out which was the last commit that is clean (the one immediately before your the commit with those lines); let's call it a876578523. Then,

git checkout a876578523
git branch -f master a876578523
git checkout master

The command simply lets your master branch (which is nothing but a "sticky note" anyways) point to that old, good, commit. After the three commands, all will be just as before your botched merge.

(To find the "good" commit, the easiest way would be to git checkout master ; gitk and just look around (and, incidently, gitk has a right-click menu, you can click on the "good" commit and pick the option "reset branch to here" or something like that). Failing that, git checkout master ; git log should work as well if you can remember your commit messages or timestamps.)

AnoE
  • 8,048
  • 1
  • 21
  • 36