Force merge file by file – git

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 ?

  • Delete everything and upload new version
  • gitolite (version 3), update admin key
  • GIT + cocos2d-x: What files can I add to gitignore?
  • How to set no “fast forward” as default when using git merge
  • Prevent Git from changing permissions on pull
  • Changing the name of the committer in Xcode
  • 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
    

  • Git extract commits as separate files
  • Is there a way to tell Capistrano to deploy a Local Repository to a Remote Server?
  • Move a Github repository to Codeplex and keep them in sync
  • Git Pull command in shell script without having to enter password manually?
  • Create git tag from within Jenkins pipeline script
  • How to always have the latest working copy of a git repo?
  • 3 Solutions collect form web for “Force merge file by file – git”

    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.

    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.

    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

    Git Baby is a git and github fan, let's start git clone.