简体   繁体   English

Eclipse的Refactor> Move可以与Git集成吗?

[英]Can Eclipse's Refactor > Move be integrated with Git?

One of the great things about using an IDE for Java is the automated refactorings you get. 使用IDE for Java的一个好处就是自动重构。 The problem I'm having is that after using Refactor > Move to move a class into a different package (which moves the file itself in the filesystem), git status shows that the file in the old location has been deleted, and the one in the new location has been added. 我遇到的问题是,在使用Refactor> Move将类移动到另一个包(在文件系统中移动文件本身)后, git status显示旧位置的文件已被删除,而新位置已添加。

The workaround I've found is clunky: 我发现的解决方法很笨重:

mv src/com/example/newpackage/Foo.java src/com/example/oldpackage/Foo.java
git mv src/com/example/oldpackage/Foo.java src/com/example/newpackage/Foo.java

Is there any way (when using the Git plugin for Eclipse) to have the refactoring do a git mv instead of a naive filesystem move? 有没有办法(当使用Eclipse的Git插件时)让重构做一个git mv而不是一个天真的文件系统移动?

That's the way how Git works with renames/moves (delete old file and add new file). 这就是Git如何使用重命名/移动(删除旧文件并添加新文件)的方式。 It then detects the contents of the file, and recognizes a rename based on an algorithm. 然后它检测文件的内容,并根据算法识别重命名。 So even it shows you delete and add, if you commit and then do a "git log --follow movedfilename", it should show you the whole history, even the history before the rename. 因此,即使它显示您删除并添加,如果您提交然后执行“git log --follow movedfilename”,它应该显示整个历史记录,甚至是重命名之前的历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM