1

I have just merged two branches 'branch1' and 'branch2'. The problem is that it is now a mess with a lot of conflicts, with sometimes duplicate contents (is it possible ??).

What I want to do is to force for some files from 'branch1' to be merged against 'branch2' and conversely to force some files from 'branch2' to be merged against 'branch1', knowing I am now on 'branch1'. Is it possible ?

Update : there seems to be problem with git-merge ? Suppose I keep the branch1 version, then

echo $this->fetch('prehome.html');
        die; 

would appear two times, see :

protected function prehomepage()
    {
        $var = 'myvar';

        echo $this->fetch('prehome.html');
        die;
    }

<<<<<<< HEAD
    $this->mySmarty->assign('title', 'Primagora');

    echo $this->fetch('prehome.html');
    die;
  }

  /**
   * Generate the campaign block for the general sidebar, called through AJAX.
   */
  protected function getCampaignBlock()
  {
    $from = Utils::fromGet('from');
    echo $this->getCampaignSidebarBlock($from);
    die();
  }
=======
    /**
     * Generate the campaign block for the general sidebar, called through AJAX.
     */
    protected function getCampaignBlock()
    {
        $from = Utils::fromGet('from');
        echo $this->getCampaignSidebarBlock($from);
        die();
    }
>>>>>>> branch2
8
  • I always prefer to resolve conflicts rather than force merge. Though you can check git-merge-file
    – Rikesh
    Commented Mar 6, 2013 at 11:12
  • The problem is that git seems to make mistakes : for example I have method that is in both branches, and now after merging it appears in only one branch, captured inside a === method >>> branch2
    – epsilones
    Commented Mar 6, 2013 at 11:16
  • git never remove your code in-spite of you have removed that method & commit in that branch & than you have merge the same in other branch.
    – Rikesh
    Commented Mar 6, 2013 at 11:18
  • Annotating your source with "conflict markers" to help you resolve conflicts isn't a mistake. It's done deliberately to help you merge.
    – CB Bailey
    Commented Mar 6, 2013 at 11:22
  • @CharlesBailey : I edited my post, there seems to be a problem with git when merging ?
    – epsilones
    Commented Mar 6, 2013 at 11:31

3 Answers 3

1

On a merge with conflicts (if git config merge.conflictstyle diff3 is set) , you can:

  • ignore that merge and keep your original version (from branch1):
git show :2:full_path > file
# or 
git checkout-index --stage=2 -- file
  • ignore that merge and keep the other version (from branch2):
git show :3:full_path > file
# or 
git checkout-index --stage=3 -- file

From there, git add and git commit.

0

You should always try to resolve conflicts. They tell you a lot about what is going on.

Netbeans can work with git which makes resolving conflicts a fairly simple task. You can resolve conflicts one by one ore choose the version you want to keep.

What do you mean by duplicate contents? It's not possible to have something marked as change if it's identical in both files.

1
  • @CharlesBailey : I edited my post, there seems to be a problem with git when merging ?
    – epsilones
    Commented Mar 6, 2013 at 11:31
0

The file you are showing is the intermediate file in an ongoing git merge whit conflicts. The lines from

<<<<<<< HEAD

to

=======

is one version and from

========

to

>>>>>branch1

is the other. You can then either edit the file by hand and pick the version to use or run a tool to help you resolve the conflicts. The git command mergetool will guide you in the process of resolving all the conflicts https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

git mergetool

git mergetool will most likely have to be configured to use your favorite conflict resolution program. I have found meld to be very helpful and intuitive.

Git mergetool with Meld on Windows or How to set Meld as git mergetool

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