How do I solve this “chicken & the egg” situation?
I decided to rename a Java class in Eclipse (say, from one.java to two.java). Eclipse refactoring let me do that without a hitch.
Then, I went to git and typed:
git mv myproj/src/com/ate/lib/one.java myproj/src/com/ate/lib/two.java
and received the error:
fatal: bad source, source=myproj/src/com/ate/lib/one.java, destination=myproj/src/com/ate/lib/two.java
I understand why this is happening, but if I do git mv before refactoring, Eclipse will not like this…
What is a good approach to tackle this?
git mvis merely a convenience method. git does not “track” renames (that is, it can detect them, but they are not recorded as an operation like an add or remove). To stage and commit your refactoring:git rmtells git to stage removing the file in the index. Although you have already “removed” the file (by moving it) in the working directory, you have not told git that you want to version this removal. The difference betweenrmandgit rmis that the first works on the working dir, and the second works on the index too (changes to be versioned by git).git addsimply adds the file content at the new location.EDIT:
I previously had
git rm --cached, out of personal habit, but apparentlygit rmdoes not complain if the file does not exist in the working dir.git rm --cachedis still useful when you want to remove a file in versioning, but keep the file in the working dir.