2013-03-06 60 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