2013-03-06 87 views
1

我刚合并了两个分支'branch1'和'branch2'。问题在于它现在已经混乱了很多冲突,有时候会有重复的内容(可能吗?)。按文件强制合并文件 - git

我想要做的是迫使'branch1'的某些文件与'branch2'合并,反过来强制一些来自'branch2'的文件合并到'branch1',知道我现在在' BRANCH1' 。可能吗 ?

更新:似乎有git-merge问题?假设我保持BRANCH1版本,然后

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

会出现两次,请参阅:

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 
+0

我总是喜欢解决冲突而不是强制合并。虽然你可以检查[git-merge-file](http://git-scm.com/docs/git-merge-file) – Rikesh 2013-03-06 11:12:39

+0

问题是git似乎犯了错误:例如我有两种方法分支,现在合并后它只出现在一个分支中,被捕获在一个===方法中>>> branch2 – Newben 2013-03-06 11:16:34

+0

git永远不会删除你的代码 - 尽管你已经删除了该方法并在该分支中提交并且你已经合并了同样在其他分支。 – Rikesh 2013-03-06 11:18:50

回答

1

在有冲突的合并(如果git config merge.conflictstyle diff3设置),您可以:

  • 忽略了合并,并保留原始版本(从branch1):
 
git show :2:full_path > file 
# or 
git checkout-index --stage=2 -- file 
  • 忽略合并,并保持其他版本(从branch2):
 
git show :3:full_path > file 
# or 
git checkout-index --stage=3 -- file 

从那里,git addgit commit

0

您应尽量化解矛盾。他们会告诉你很多关于正在发生的事情。

Netbeans可以使用git来解决冲突,这是一项相当简单的任务。您可以逐个解决冲突并选择您想要保留的版本。

你是指重复的内容是什么意思?如果两个文件中的内容完全相同,则无法将其标记为更改。

+0

@CharlesBailey:我编辑了我的帖子,似乎在合并时遇到git问题? – Newben 2013-03-06 11:31:51

0

您显示的文件是正在进行的git merge whit冲突中的中间文件。从

<<<<<<< HEAD 

======= 

线是一个版本,并从

======== 

>>>>>branch1 

是其他。然后,您可以手动编辑文件并选择要使用的版本,也可以运行工具来帮助您解决冲突。 的git的命令合并工具将指导您解决所有冲突 https://www.kernel.org/pub/software/scm/git/docs/git-mergetool.html

git mergetool 

混帐合并工具的过程将最有可能被配置为使用自己喜欢的冲突解决方案。我发现融合是非常有帮助和直观的。

Git mergetool with Meld on WindowsHow to set Meld as git mergetool