在 Eclipse 中方便地将类移动到不同的包,而无需 svn

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/420013/
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-19 13:28:04  来源:igfitidea点击:

Conveniently move a class to a different package in eclipse without borking svn

javaeclipsesvnmove

提问by Schneehenry

When moving a file from old.package to new.packageI want two things to happen:

old.package to new.package我移动文件时,我希望发生两件事:

  1. Update all references to that class (in all files of the project) so that the new package is used
  2. svn move old/package/Foo.java new/package/Foo.java
  1. 更新对该类的所有引用(在项目的所有文件中),以便使用新包
  2. svn move old/package/Foo.java new/package/Foo.java

I use subversive within Eclipse Ganymede. When I just drag the file from one package to the other, all references get updated and the file is moved around on the filesystem. But SVN is unaware of this and therefore the svn move old/package/foo.java new/package/Foo.javacommand does not work (obviously) when old/package/Foo.javadoes not exist (because eclipse has moved it already).

我在 Eclipse Ganymede 中使用了 subversive。当我只是将文件从一个包拖到另一个包时,所有引用都会更新并且文件在文件系统上移动。但是 SVN 不知道这一点,因此该svn move old/package/foo.java new/package/Foo.java命令在old/package/Foo.java不存在时(显然)不起作用(因为 eclipse 已经移动了它)。

Is there a way to have eclipse do it's refactoring but using svn to move the file on the filesystem? I hope I'm just missing something obvious :-)

有没有办法让 eclipse 进行重构但使用 svn 移动文件系统上的文件?我希望我只是错过了一些明显的东西:-)

采纳答案by Yuval Adam

I use Subclipseand it doessupport moving files between packages

我使用Subclipse,它确实支持在包之间移动文件

回答by orbfish

I've been experimenting, and think I've found the way:

我一直在试验,并认为我已经找到了方法:

1) Tortoise-move the file using the right-click-drag context menu (or whatever SVN method you want).

1) 使用右键单击并拖动上下文菜单(或任何您想要的 SVN 方法)来移动文件。

2) Use the windows filesystem to move it back.

2) 使用 windows 文件系统将其移回。

3) Drag-move the file in Eclipse to update all the references.

3) 在 Eclipse 中拖动文件以更新所有引用。

4) Commit - it shows as a delete/add, but it saves the history, and it does change the package references in one commit (keeping each commit buildable).

4)提交 - 它显示为删除/添加,但它保存历史记录,并且它确实在一次提交中更改了包引用(保持每个提交可构建)。

Old question, but I keep returning to it, so this is my documentation!

老问题,但我一直回到它,所以这是我的文档!

回答by John Stoneham

Yuval's right. This sounds like a (very unfortunate!) deficiency in Subversive. (having no experience with Subversive I can't say for sure) Subclipse definitely handles this properly by hooking into the right APIs in Eclipse.

尤瓦尔是对的。这听起来像是 Subversive 的一个(非常不幸!)缺陷。(没有使用 Subversive 的经验我不能肯定)Subclipse 通过在 Eclipse 中连接到正确的 API 来正确地处理这个问题。

回答by Bombe

You can not do both at the same time because moving the files alone is not enough. The files need to be modified in order for your code to be compilable again. So refactor with Eclipse and let Subclipse do its magic (remove old files, add new files) after the move.

您不能同时执行这两项操作,因为仅移动文件是不够的。需要修改这些文件才能再次编译您的代码。因此,使用 Eclipse 进行重构,并让 Subclipse 在移动后发挥其魔力(删除旧文件、添加新文件)。

回答by Kezzer

If you let Eclipse do the refactoring then surely it will make changes in the actual files which SVN should pick up when you commit the root directory? I don't think a move will cut it though, SVN will have to pick up that the file is missing from its original directory but re-add it from the new directory. It's a sticky situation, I wouldn't know what the best method is, I'd just do the refactoring and then commit the root personally, even though it wouldn't be a move.

如果您让 Eclipse 进行重构,那么它肯定会在提交根目录时对 SVN 应该选取的实际文件进行更改?我不认为移动会削减它,SVN 将不得不从其原始目录中提取该文件,但从新目录中重新添加它。这是一个棘手的情况,我不知道最好的方法是什么,我只是进行重构然后亲自提交根,即使这不会是一个举动。