在 Eclipse 中进行 Subversion 合并的正确方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/98489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:24:13  来源:igfitidea点击:

What is the proper way to do a Subversion merge in Eclipse?

eclipsesvnmergesubversive

提问by awied

I'm pretty used to how to do CVS merges in Eclipse, and I'm otherwise happy with the way that both Subclipse and Subversive work with the SVN repository, but I'm not quite sure how to do merges properly.

我非常习惯于如何在 Eclipse 中进行 CVS 合并,而且我对 Subclipse 和 Subversive 与 SVN 存储库一起工作的方式感到满意,但我不太确定如何正确进行合并。

When I do a merge, it seems to want to stick the merged files in a seperate directory in my project rather than overwriting the old files that are to be replaced in the merge, as I am used to in CVS.

当我进行合并时,它似乎想将合并的文件粘贴在我的项目中的单独目录中,而不是像我在 CVS 中习惯的那样覆盖要在合并中替换的旧文件。

The question is not particular to either Subclipse or Subversive.

这个问题并不特别针对 Subclipse 或 Subversive。

Thanks for the help!

谢谢您的帮助!

采纳答案by MetroidFan2002

I would advise not trying to use Eclipse's plugins as your primary access to Subversion.

我建议不要尝试使用 Eclipse 的插件作为您对 Subversion 的主要访问。

If you are developing on Windows, TortoiseSVN is the best program that I have seen for Subversion access. Explore to the directory of which you wish to merge, right click on it and use the Tortoise SVN merge option. Assuming a non-interactive merge, once you get conflicts, you'll have to go through each conflicted file and edit the conflicts before marking them as resolved. For this process I recommend a program called KDiff3, which shows your local repository copy (what was stored in the .svn before the merge), your local copy (including any changes), and the copy coming from the repository, and allows you to easily see (and even hand-modify if needed) the result of the merging. It also handles a bunch of minor conflicts automatically.

如果你在 Windows 上开发,TortoiseSVN 是我见过的最好的 Subversion 访问程序。浏览到您希望合并的目录,右键单击它并使用 Tortoise SVN 合并选项。假设是非交互式合并,一旦遇到冲突,您必须检查每个冲突文件并编辑冲突,然后再将它们标记为已解决。对于这个过程,我推荐一个名为 KDiff3 的程序,它显示您的本地存储库副本(合并之前存储在 .svn 中的内容)、您的本地副本(包括任何更改)以及来自存储库的副本,并允许您轻松查看(甚至在需要时手动修改)合并的结果。它还自动处理一堆小冲突。

KDiff3 is portable, TortoiseSVN is a windows shell extension, so if you're using another environment, I would try to just use SVN to merge. But that would be much more of a pain :)

KDiff3 是可移植的,TortoiseSVN 是一个 windows shell 扩展,所以如果你使用其他环境,我会尝试只使用 SVN 进行合并。但这会更痛苦:)

回答by DH4

Merging an entire branch into trunk

将整个分支合并到主干中

  1. Inspect the Branch project history to determine the version from which the branch was taken

    • by default Eclipse Team "History" only shows the past 25 revisions so you will have to click the button in that view labeled "Show All"
    • when you say "Show All" it will take you back past the branch date and show you all the history for trunk as well so you'll have to search for your comment where you branched
    • NOTE: if you use Tortise SVN for this same task (navigate to the branch and select "Show Log") it will show you only the branch history so you can tell exactly where the branch began
  2. So now I know that 82517 was the first version ID of the branch history. So all versions of the branch past 82517 have changes that I want to merge into trunk

  3. Now go to the "trunk" project in your Eclipse workspace and select "right click - Team - Merge"

  4. The default view is the 1 url merge

    • select the URL of the branch from which you are merging
    • under Revisions select "All"
    • press OK
  5. This will take you to the "Team Synchronizing" perspective (if it doesn't you should go there yourself) in order to resolve conflicts (see below)

  1. 检查分支项目历史记录以确定分支的版本

    • 默认情况下,Eclipse 团队“历史”仅显示过去的 25 个修订版,因此您必须单击该视图中标记为“全部显示”的按钮
    • 当您说“全部显示”时,它会将您带回分支日期,并向您显示主干的所有历史记录,因此您必须在分支的位置搜索您的评论
    • 注意:如果您将 Tortise SVN 用于同一任务(导航到分支并选择“显示日志”),它将仅显示分支历史记录,以便您可以准确地知道分支的开始位置
  2. 所以现在我知道 82517 是分支历史的第一个版本 ID。所以分支的所有版本超过 82517 都有我想合并到主干的更改

  3. 现在转到 Eclipse 工作区中的“主干”项目并选择“右键单击 - 团队 - 合并”

  4. 默认视图是 1 url 合并

    • 选择要合并的分支的 URL
    • 在修订下选择“全部”
    • 按确定
  5. 这将带您进入“团队同步”视角(如果没有,您应该自己去那里)以解决冲突(见下文)

Re-Merging more branch changes into trunk

将更多分支更改重新合并到主干中

  1. Insepct the trunk project history to determine the last time you merged into trunk (you should have commented this)

    • for the sake of argument let's say this version was 82517
  2. So now I know that any version greater than 82517 in the branch needs to be merged into trunk

  3. Now go to the "trunk" project in your Eclipse workspace and select "right click - Team - Merge"

  4. The default view is the 1 url merge

    • select the URL of the branch from which you are merging
    • under Revisions select "Revisions" radio button and click "Browse"
    • this will open up a list of the latest 25 branch revisions
    • select all the revisions with a number greater than 82517
    • press OK (you should see the revision list in the input field beside the radio button)
    • press OK
  5. This will take you to the "Team Synchronizing" perspective (if it doesn't you should go there yourself) in order to resolve conflicts (see below)

  1. 检查主干项目历史记录以确定您上次合并到主干中的时间(您应该对此进行评论)

    • 为了论证起见,假设这个版本是 82517
  2. 所以现在我知道分支中任何大于82517的版本都需要合并到trunk

  3. 现在转到 Eclipse 工作区中的“主干”项目并选择“右键单击 - 团队 - 合并”

  4. 默认视图是 1 url 合并

    • 选择要合并的分支的 URL
    • 在修订下选择“修订”单选按钮,然后单击“浏览”
    • 这将打开最新 25 个分支修订的列表
    • 选择所有编号大于 82517 的修订
    • 按确定(您应该在单选按钮旁边的输入字段中看到修订列表)
    • 按确定
  5. 这将带您进入“团队同步”视角(如果没有,您应该自己去那里)以解决冲突(见下文)

Resolving Conflicts

解决冲突

  1. You should be at the "Team Synchronizing" perspective. This will look like any regular synchronization for commit purposes where you see files that are new and files that have conflicts.

  2. For every file where you see a conflict choose "right click - Edit Conflicts" (do not double click the file, it will bring up the commit diff version tool, this is VERY different)

    • if you see stuff like "<<<<<<< .working" or ">>>>>>> .merge-right.r84513" then you are in the wrong editing mode
  3. once you have resolved all the conflicts in that file, tell the file to "mark as merged"

  4. once all the files are free of conflicts you can then synchronize your Eclipse project and commit the files to SVN

  1. 您应该处于“团队同步”的角度。这将类似于用于提交目的的任何常规同步,其中您会看到新文件和存在冲突的文件。

  2. 对于您看到冲突的每个文件,选择“右键单击 - 编辑冲突” (不要双击该文件,它会显示提交差异版本工具,这是非常不同的)

    • 如果您看到诸如“<<<<<<< .working”或“>>>>>>>> .merge-right.r84513”之类的内容,那么您处于错误的编辑模式
  3. 一旦您解决了该文件中的所有冲突,请告诉该文件“标记为已合并”

  4. 一旦所有文件都没有冲突,您就可以同步您的 Eclipse 项目并将文件提交到 SVN

回答by Joe Skora

I typically check out both branches and then use the compare to each other option which does a synchronize-like compare of the two source trees. After integrating the changes into one branch, you can recommit back to the repository.

我通常检查两个分支,然后使用相互比较选项,该选项对两个源树进行类似同步的比较。将更改集成到一个分支后,您可以重新提交回存储库。

回答by David Pierre

Use Eclipse integration, it works perfectly fine.

使用 Eclipse 集成,它工作得很好。

The main change from CVS, is that you only merge deltas from a branch, ie changes from one revision to another. That is to say you have to track the correct start revision somehow (unless you have svn 1.5 merge history)

CVS 的主要变化是您只合并来自一个分支的增量,即从一个修订版更改为另一个修订版。也就是说你必须以某种方式跟踪正确的开始修订(除非你有 svn 1.5 合并历史)

If you got that right, it's only up to you to get the changes right with the compare editor.

如果您做对了,则只能由您来使用比较编辑器正确进行更改。

回答by Some Guy

Firstly, if you are seeing ">>>>>" and such in your files when you view them in Eclipse, this probably means that you are not looking at the file with the proper compare editor. Try right-clicking on the file in the Project view or Synchronize view and selecting "Edit Conflicts" to bring up a compare editor that will show you the conflicting regions graphically rather than as text. Note that the compare editor that comes up for "Edit Conflicts" is different from the one that you get when you just doubleclick on a file in the Synchronize view -- the doublieclick compare editor shows the differences between your current file and the way it existed when you last checked it out or updated it, while the Edit Conflicts compare dialog shows the differences between two sources of changes (for instance, the changes you merged versus the changes that existed in your workspace before you merged).

首先,如果您在 Eclipse 中查看文件时看到“>>>>>”等,这可能意味着您没有使用正确的比较编辑器查看文件。尝试在“项目”视图或“同步”视图中右键单击文件并选择“编辑冲突”以调出比较编辑器,该编辑器将以图形而非文本形式显示冲突区域。请注意,“编辑冲突”的比较编辑器与您在“同步”视图中双击文件时获得的编辑器不同——doubleclick 比较编辑器显示当前文件与其存在方式之间的差异上次检出或更新时,“编辑冲突比较”对话框显示两个更改源之间的差异(例如,

Secondly, you may wish to be aware of a bug in some versions of the Eclipse subversive plugin which causes all files that accepted merge changes to be incorrectly marked as having conflicts. This bug has been fixed, but a lot of people don't seem to have updated to get the fix yet. Further details here:

其次,您可能希望了解某些版本的 Eclipse 颠覆性插件中的一个错误,该错误导致所有接受合并更改的文件被错误地标记为存在冲突。这个错误已被修复,但很多人似乎还没有更新以获得修复。详情请见:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=312585

https://bugs.eclipse.org/bugs/show_bug.cgi?id=312585

回答by T0xicCode

openCollabNet's merge tool for subclipse is pretty neat. There are many merging types available and the merging I just performed with it when seamlessly. I recommend it.

openCollabNet 的 subclipse 合并工具非常简洁。有许多可用的合并类型,我刚刚使用它无缝地进行合并。我推荐它。

回答by Jean

Remember that with svn reverting a modified tree to a clean state is fairly easy. Simply have a clean workspace on the merge destination branch and run the merge command to import the modifications from the merge source branch, then synchronize your workspace and you will get your usual eclipse comparison window showing all the merge modified files and the conflicts.

请记住,使用 svn 将修改后的树恢复到干净状态是相当容易的。只需在合并目标分支上有一个干净的工作区并运行合并命令从合并源分支导入修改,然后同步您的工作区,您将获得通常的 Eclipse 比较窗口,显示所有合并修改的文件和冲突。

If for some reason you can't solve the conflicts you can svn revert on the project and go back to a clean state, otherwise you do the merge in place and once you are done you can commit. Note that you don't have to commit, once you are done handling the conflicts you can also return to the dev view, verify that the code compiles, run your unit tests, whatever and then synchronize again and commit (once the conflict are locally resolved they won't come back)

如果由于某种原因您无法解决冲突,您可以在项目上使用 svn revert 并返回到干净的状态,否则您就地进行合并,完成后您可以提交。请注意,您不必提交,一旦处理完冲突,您还可以返回开发视图,验证代码是否编译,运行单元测试,然后再次同步并提交(一旦冲突发生在本地解决他们不会回来)

last time I looked, when you use subclipse merge command it will overwrite the merged file (using conflict markers to show conflicting areas) and put the original left and right side of the merge in the same place. it shouldn't put anything in different directories.

上次我看,当您使用 subclipse merge 命令时,它会覆盖合并的文件(使用冲突标记来显示冲突区域)并将合并的原始左侧和右侧放在同一位置。它不应该把任何东西放在不同的目录中。

As a rule of thumb, it is best to commit all merge modifications in a single commit and to only have the merge modifications in the commit so that you can rollback the merge later if needed.

根据经验,最好在一次提交中提交所有合并修改,并且只在提交中包含合并修改,以便以后可以在需要时回滚合并。

回答by nku

The one thing that syncrhonize view in eclipse lacks is check-in capability. In Team synchronization view I can view all my changes and resolve conflicts, so it would be rather intuitive to check-in right there instead of going back to java view and do check-in.

在 Eclipse 中同步视图缺少的一件事是签入功能。在团队同步视图中,我可以查看我的所有更改并解决冲突,因此直接在那里签入而不是返回 Java 视图并进行签入会非常直观。

回答by fl0w

I landed here because I was looking for a way to merge in an external merge editor (KDIFF3) but start the merge from eclipse. I wasn't satisfied with the answers provided above. So here is ho to configure kdiff3 as merge and diff editor for SVN in eclipse:

我来到这里是因为我正在寻找一种在外部合并编辑器 (KDIFF3) 中合并但从 eclipse 开始合并的方法。我对上面提供的答案并不满意。所以这里是 ho 在 Eclipse 中将 kdiff3 配置为 SVN 的合并和差异编辑器:

go to Windows -> Preferences → Team -> SVN -> Diff Viewer Add a new config (add button): Extension or mimetype: * - if you wish you can specify different mimetypes for different editors, I didn't need that thus the alquantor.

转到 Windows -> Preferences → Team -> SVN -> Diff Viewer Add a new config (add button): Extension or mimetype: * - 如果你希望你可以为不同的编辑器指定不同的 mimetypes,我不需要,因此alquantor。

Diff: Program path C:\Program Files\KDiff3\kdiff3.exe (or wherever you have your merge editor - sry for the windows path, feel free to add a linux version in the comments or edit this answer.)

Diff: 程序路径 C:\Program Files\KDiff3\kdiff3.exe (或者任何你有合并编辑器的地方 - sry 对于 Windows 路径,随时在评论中添加一个 linux 版本或编辑这个答案。)

Arguments: ${base} ${mine} ${theirs}

参数: ${base} ${mine} ${theirs}

Merge: Program path C:\Program Files\KDiff3\kdiff3.exe

合并:程序路径 C:\Program Files\KDiff3\kdiff3.exe

Arguments: ${base} ${mine} ${theirs} -o ${merged}

参数: ${base} ${mine} ${theirs} -o ${merged}

This will probably work as well for other merge editors, but with a different argument syntax (figure it out an let us know :) ).

这可能也适用于其他合并编辑器,但使用不同的参数语法(弄清楚让我们知道 :))。

The usage is as usual (team->edit conflicts) for merging and compare->foo for the diff view.

合并和比较-> foo 用于差异视图的用法和往常一样(团队-> 编辑冲突)。

Cheers

干杯