2012-07-31 72 views
-1

通過愚蠢,一個大文件的唯一版本是從試圖合併,也就是說,它包含了大量的行狀從混帳清理文件合併

<<<<<<< HEAD  double[] p1 = ... 
        double[] p2 = ... 
=======   double[] p1 = ... 
       double[] p2 = ... 
>>>>>>> origin/foo 

如何擺脫這些,而不必編輯每一個,總是選擇HEAD

合併和一些愚蠢的命令讓我沒有了我的原始HEAD的蹤跡,幸運的是git reflog幫助我找到合併之前的位置。

+0

你可以使用合併工具 – 2012-07-31 11:12:09

+0

沒有文件需要合併。請再次閱讀該問題。 – rwst 2012-07-31 13:26:20

+0

我在你做出編輯之前已經回答了,並且我建議你再次重新閱讀你的問題'...一個大文件的唯一版本是試圖合併...' – 2012-07-31 13:28:14

回答

1

如果您要始終選擇HEAD,那麼您正在尋找名爲oursmerge strategy

git merge -s ours <branch-to-merge>

報價在合併git的幫助:

合併策略 合併機制(GIT合併和git-pull命令)允許後端的合併策略與-s選項選擇。一些 策略也可以採用自己的選項,可以通過將-X參數傳遞給git-merge和/或git-pull來傳遞。

recursive 
     This can only resolve two heads using a 3-way merge algorithm. When there is more than one common ancestor that can be used 
     for 3-way merge, it creates a merged tree of the common ancestors and uses that as the reference tree for the 3-way merge. 
     This has been reported to result in fewer merge conflicts without causing mis-merges by tests done on actual merge commits 
     taken from Linux 2.6 kernel development history. Additionally this can detect and handle merges involving renames. This is 
     the default merge strategy when pulling or merging one branch. 

     The recursive strategy can take the following options: 

     ours 
      This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree 
      that do not conflict with our side are reflected to the merge result. 

      This should not be confused with the ours merge strategy, which does not even look at what the other tree contains at 
      all. It discards everything the other tree did, declaring our history contains all that happened in it. 

     theirs 
      This is opposite of ours. 

    ours 
     This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, 
     effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of 
     side branches. Note that this is different from the -Xours option to the recursive merge strategy. 

這些都是一些上市的策略。 使用git help merge尋找更多。

+0

沒有文件需要合併。請再次閱讀該問題。 – rwst 2012-07-31 13:26:31

+0

除非嘗試合併,否則不能在文件中留下這些行。如果你留下這些東西,你並沒有正確合併。我建議你回滾合併,然後再用'我們的'合併策略來做(根據你在問題中提到的內容)。否則,您必須手動編輯文件,並且很容易出錯。 – Sailesh 2012-07-31 13:43:28

+0

我需要reflog來查找合併之前的狀態。然後這一切工作。謝謝 – rwst 2012-07-31 14:18:52

0

您可以通過將-X ignore-space-change傳遞到命令行來合併時忽略空間更改,這也適用於git rebase