Eclipse的Git插件Egit: merge合併衝突具體解決方法

http://www.cnblogs.com/wavky/p/3504060.htmlhtml

 

稍微總結下弄了半個下午的egit的merge合併衝突解決方法,網上看的都是一個模板出來的,看的糊里糊塗,花了不少時間去實驗整個合併流程..java

 

前提工做

  • 建立一個普通JAVA工程Test,建立一個類Test,寫點東西並加入到本地git庫;
  • 建立個develop分支,建立個Develop類,修改Test類的某些語句,添加新代碼段,提交;
  • 切換到master分支,建立個Master類,修改Test類的同一部分語句,提交;

以上三條操做不進行詳細說明,很簡單的。node

 

 

合併過程

打開git repository exploring視圖:git

 

在Test庫中,在develop分支上打開右鍵菜單,點擊Merge:app

 

出現衝突提示框:eclipse

  

返回JAVA工程項目視圖,能夠看見Test工程已經自動進行了部分合並,添加了Develop類,但Test類存在衝突(有紅色雙箭頭標記的文件纔是衝突,茶色星星標記的文件沒有實際衝突項),選中工程打開右鍵菜單,打開Merge Tool:ide

 

Merge Tool界面顯示以下,左邊爲衝突文件的當前版本(master分支),右邊爲準備合併過來的目標版本(develop分支),手工把右邊的代碼copy到左邊,或至少隨意更改下左邊的文件,保存。   注:右邊的窗口有時候標題顯示的版本節點不正確,多是BUG,或者筆主理解能力不足所致。wordpress

 

在Merge Tool中更改並保存後,當前衝突的Test類以下圖中的各類神奇標記符號將自動消除:fetch

 

上圖的紅色神奇符號已經自動合併消除,並呈現相似下圖的合併效果:ui

 

Window->Show View->Other,打開Git Staging視圖:

 

Git Staging視圖中,Unstaged Changes部分包含衝突文件(包括手工合併先後),Staged Changes部分包含已經完成自動合併的文件,在已經合併完成的衝突文件Test.java上打開右鍵菜單,選中Add to Git Index:

 

Test.java被添加到Staged Changes下面,並自動生成Commit Message等內容,確認無誤後點擊Commit提交:

 

至此,Merge合併的衝突已經徹底解決,從develop到master方向的合併已經完成:

 

若要從master合併到develop,只需切換到develop分支,(在git repository exploring視圖中)在master菜單上點擊Merge便可。筆主使用的Egit2.2版本默認進行Fast-Forward方式的合併,最新的3.2版已經提供是否選擇Fast-Forward的UI窗口。

* 關於Egit3.2的Fast-Forward合併:提供該選擇的UI窗口僅在JAVA視圖窗口中,經過項目工程右鍵菜單中執行Team->Merge觸發顯示,經過上面使用git repository exploring視圖簡單調用Merge的方式仍然使用默認的Fast-Forward合併:

 

==============================================

https://allaboutmynonexistedworld.wordpress.com/2014/02/05/eclipse-git-merging-branch-to-master/

 

 

 

1. Make sure the current pointer is at master.01

2. Right click on the project to be merged. Select Team -> Merge02

3. In the pop up window, double click on the branch you want to merge.03

4. A merge conflict window should jump up. Click OK to continue04

5. Right click on the project with a red mark. Select Team -> Merge Tool05

6. In 「Select a Merge Mode」 window, select Use HEAD option and hit OK06

7. Edit it in the editor however you want (play around with the options)07

8. Once you decided the conflict is resolved, right click on the red mark file, select Team -> Add to Index08

9. Finally, you should be able to commit the changes and push to the upstream.

 

===========================

Problem resolve 「egit remote tracking show nothing」

有時候在用Team => Switch to => 時, 看不到想要的branch, 用以下方法解決.

https://stackoverflow.com/questions/47390703/how-do-i-get-a-new-branch-to-show-up-in-eclipse-git-remote-tracking?rq=1

 

How do I get a new branch to show up in Eclipse Git Remote Tracking?

 

I have an existing Eclipse git project, with a master and development branch present in both local, and remote tracking. I have just added a new branch in my git repository, but I can't figure out how to get it to show up in Eclipse.

I have tried to read up on the subject, but it seems like it is just expected to automatically show up. I have found a lot of similar questions, but they all seem to deal with the issues of a completely empty remote tracking folder, instead of my problem of only a single new branch missing. I already have Master and Develop present.

Here is what does not work:

  • Clicking refresh in the Git repositories window.
  • Any kind of synchronize, pull or other update I can find

Here is what would work:

  • Right clicking the remote tracking folder, and selecting "Paste repository path or URI". If I do that, and select the exact same path as is already there, I can see my new branch. This action does require that I completely clone the whole repository to an empty folder again, and that can't be how this is intended to work.
  • I believe it might work to use some kind of command line tool, but I really want an Eclipse solution to this, as I feel sure it exists, and I am just missing something.

20

In the Git Repositories view:

  1. Right-click the repository and choose Fetch from Upstream
  2. If the new branch will not shown up below Branches/Remote Tracking, you have to configure fetch:
    1. Right-click the fetch node below Remotes/origin and choose Configure Fetch...
    2. In the Configure Fetch make sure there is only the single Ref mapping +refs/heads/*:refs/remotes/origin/*:

 

God damnit, in my latest attempts, I just confused two different repositories. So this really does work. Thanks a lot! – KjetilNordin Nov 20 '17 at 11:56

add a comment

 

在執行了一次上面的fetch後,  在用Team => Switch to => 時, 能夠看到了branch.

相關文章
相關標籤/搜索