8

I have two laptops, each work on the master branch. This morning I forgot to push changes made to the branch before working on the other laptop. So I have two different versions of code. So I pushed the code from the second laptop and then on the first laptop was going to try and merge that version into the remote version.

I tried to merge but I think I bungled it up. I have the following code:

<<<<<<< HEAD
.publicHome-input-neutral {
=======
.signin-input {
>>>>>>> fae264c582726a42c3d09f2ffbbe5b429a471598
    line-height: 40px;
    height: 40px;
    font-size: 18px;
    padding: 0px 16px;
    border: 1px solid @color-instanty-blue;
    border-radius: 6px;
    background: #ffffff;
    text-align: center;
    width: 250px;
    color: @color-text-dark;
}

<<<<<<< HEAD
=======
.signin-input.ng-invalid {
    border-color: red;
}

As you can see, it's still messy. I have p4merge installed and tried starting it via git mergetool. I got the message though No files need merging.

Can one revert to earlier stages before I messed up the merge? Or somehow resolve these files which were wrongly merged?

SherylHohman
  • 16,580
  • 17
  • 88
  • 94
basickarl
  • 37,187
  • 64
  • 214
  • 335

4 Answers4

4

Your file ended up in the staged area. To be sure check with

git ls-files --stage <file>

Then add it back as an unmerged file using the -m option from checkout.

git checkout -m <file>
jaques-sam
  • 2,578
  • 1
  • 26
  • 24
1

You can also do

git difftool

And it brings you up the files one by one and you can resolve manually. It is useful when auto merge fails or conflicts are too hard to resolve. However you have to make sure it is set as follows, the below example is for Beyond compare in mac

git config --global diff.tool bc
git config --global difftool.prompt false
git config --global difftool.bc trustExitCode true
git config --global merge.tool bc
git config --global mergetool.bc trustExitCode true
Matt
  • 99
  • 1
  • 9
0

It sounds like you added + committed changes with git conflict notation in the files. This in itself is not a huge issue at all (we've all done it). You have two main options, as I see it:

1) Search your files for patterns along the lines of "<<<<", "====", ">>>>" and manually assess and fix each conflict, then simply commit these changes.

2) Revert to before you merged. To do this simply enter git log, and find the commit where you performed the merge and copy the SHA of that commit to your clipboard, then enter:

git revert -m 1 <your SHA here>

Then perform the merge again, but this time make sure all of the git conflict notation before entering git add, as this command indicates that you have resolved the conflicts.

PS. If you want to look at the commit you're about to revert to, before actually performing the revert, simply enter git checkout <your SHA here> and have a look around. Once you're satisfied that this is where you want to be, enter git checkout master to get back to where you were.

J.M. Janzen
  • 671
  • 1
  • 8
  • 19
-1

Read it all in here: How to revert to old commit

The relevant part for you is the git reflog which will allow you to go back to any desired point in time where you modified your HEAD.



git reflog

You can always use the reflog as well.
git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167