gitrefactoringgit-rmgit-mv

Move a file from a directory with one file to another (refactoring)


I have a directory with a single file Foo.java defining a class under package com.a.b.c under a specific package i.e. src/com/a/b/c/Foo.java
I want to refactor and move the class in a different package e.g. com.x.y.x i.e. src/com/x/y/z/Foo.java
I did the refactor from inside the IDE I am using and that led to the git status showing:

src/com/a/b/c/Foo.java -> src/com/a/b/c/Foo.java

Now the issue is that the src/com/a/b/c is still there and empty.
I know that git has an issue with empty directories so now I am not sure how should I remove that? Should I do git rm -r src/com/a/b/c and commit everything at once? Or is there a better way?


Solution

  • Git does not track directories, it tracks files. If you have moved everything away from src/com/a/b/c, you can just remove that directory from your working tree in any way you want, i.e. rmdir src/com/a/b/c - it has no effect on git whatsoever.