Git: Unable to clean working copy after refactoring file names


I somehow cause git to get all confused after renaming a directory in a Java project. There are now a whole bunch of phantom files sitting in my working copy for the old file name that I can't seem to remove.

An example of one these changes is:

Example Diff:

-package com.RedactedCompanyName.Helpers; +package com.RedactedCompanyName.helpers;

Its basically just committing the location change. But every time I try to commit this change, git (and source tree) just ignores it and they remain as uncommitted modifications

I've tried all the various git suggestions around StackOverflow:

git reset --head head git clean -rf

None of them seem to work.

Even resetting to previous commit before this refactor, doing it properly and then merging back won't work because this file corruption is preventing a merge.

I even tried a 'scored earth' approach as well where I just cloned a new local copy of the repo. The second I made my first commit, this noise re-appeared.

Show source
| java   | android   | git   | unix   | refactoring   2017-01-03 05:01 1 Answers

Answers ( 1 )

  1. 2017-01-03 05:01

    Sadly, you have to use git mv when you rename your classes (because the standard tools don't typically know to do that when renaming/refactoring Java files). If you can't do that, then you'll have to use git rm to remove the old files.

    For example,

    git mv
    git commit -m "Renamed OldNumberUtils to NumberUtils"

    or, in your case (because git doesn't know about the rename)

    git rm
    git commit -m "Removing OldNumberUtils, because it was renamed NumberUtils"
◀ Go back