Different folder names in Git and IntelliJ IDEA

770 Views Asked by At

I develop a project in IntelliJ IDEA and use Git as a VCS. I have a package "currencies" in IDEA, but it is called "Currencies" in Git.

Somehow Git understands that it is the same folder, but IDEA doesn't. This mismatch creates lots of problems. How can I make this folder be name identically in Git and IDEA?

2

There are 2 best solutions below

3
On

Tell Git to explicitly rename a directory.

Try with -n key to see what will be the result. Use * in the source path argument and not in the destination.

git mv -f -n path/to/Currencies/* path/to/currencies/

Once everything is as you want, run the same without -n:

git mv -f path/to/Currencies/* path/to/currencies/

Now checkout any other revision and then this one again. The folder should be renamed to lowercase.

An example with original paths from the question:

Preparing an example:

➜  git_mv_uppercase git:(master) mkdir src
➜  git_mv_uppercase git:(master) mkdir src/Currencies
➜  git_mv_uppercase git:(master) echo "1">src/Currencies/1
➜  git_mv_uppercase git:(master) echo "2">src/Currencies/2
➜  git_mv_uppercase git:(master) ✗ git add --all
➜  git_mv_uppercase git:(master) ✗ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    new file:   src/Currencies/1
    new file:   src/Currencies/2

➜  git_mv_uppercase git:(master) ✗ git commit -m'uppercase'

Now we've got path src/Currencies tracked by Git. And we want to rename it.

➜  git_mv_uppercase git:(master) git mv -f src/Currencies/* src/currencies/
➜  git_mv_uppercase git:(master) ✗ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
    renamed:    src/Currencies/1 -> src/currencies/1
    renamed:    src/Currencies/2 -> src/currencies/2
➜  git_mv_uppercase git:(master) ✗ git commit -m'renamed to lowercase'

Git has tracked the rename (but it will not rename the folder in working tree yet).

➜  git_mv_uppercase git:(master) ls src
Currencies

Now checkout to some other revision and back:

➜  git_mv_uppercase git:(master) git checkout HEAD^
➜  git_mv_uppercase git:(master) git checkout master

We can see that folder is successfully renamed:

➜  git_mv_uppercase git:(master) ls src
сurrencies
0
On

I found quite an ugly solution: just created a new folder "ccys" and copied all the classes from Currencies to ccys. Then deleted Currencies and fixed imports in the code.