11

I'm doing a git rebase, and I'm stuck because in one commit I have a folder named Proto, but in the other commit I have a folder named proto. It was an honest mistake and should have been Proto in both cases. The best I can figure out here is to try deleting the folder from both commits and then trying the rebase again, but there has to be a better way.

In the past, when I've run into capitalization problems with a file, I've used git mv, but with the folder it won't let me run git mv, and I don't know why.

What's the correct way to fix a folder capitalization problem in git on Windows?

Smuuf
  • 6,339
  • 3
  • 23
  • 35
Jonathan Beerhalter
  • 7,229
  • 16
  • 68
  • 78

5 Answers5

18

We encountered a similar issue in our git repository on Windows when a large number of files were moved around to different directories.

I fixed our issue the first time manually by cloning the repository to a Linux VM and running a bash script with git mv commands to fix the file path case issue. This was a painful process so I decided to develop a utility that automates the process.

Git Unite is a .NET console application I wrote using the libgit2sharp library. The program identifies all git index entries with file path case different from what the Windows file system reports.

I wrote a blog posting detailing the tool, usage, and history behind it at Git Unite - Fix Case Sensitive File Paths on Windows

tawman
  • 2,478
  • 1
  • 15
  • 24
1

Smuggling folder renames into Git history is difficult, because folders are not tracked -- only files in the folders. Assuming that you want to rename oldFolder to oldfolder you could try the following:

  1. Rebase interactively from the point where you first created a file in oldFolder. Edit every commit that adds files to this folder. When interactive rebase stops, create newFolder and execute git mv oldFolder/* newFolder/. Do the latter for each stop of the interactive rebase.

  2. Obviously, you cannot have oldFolder and newFolder be two differently capitalized versions of the same word in Windows. Hence, repeat step 1 to rename newFolder to oldfolder.

krlmlr
  • 25,056
  • 14
  • 120
  • 217
  • Thanks for the help, turns out I had to go back and delete the folder from one branch, perform the rebase, then manually add the files back in post rebase. – Jonathan Beerhalter Dec 13 '12 at 16:54
0

git config --global core.ignorecase true should solve your problem on Windows.

hd1
  • 33,938
  • 5
  • 80
  • 91
0

[Edited] I suspect you need to "git mv" each file in the folder to a temp name like 'ProtoX', then "git mv" the temp-named files to 'Proto', as Git does not track folders by themselves -- only the files in the folders.

The double "git mv" works around Windows case-insensitive filesystems. (You should be able to move directly from 'proto' to 'Proto' on case-sensitive filesystems, like Linux.)

Mark Leighton Fisher
  • 5,609
  • 2
  • 18
  • 29
0

Instead of using git mv on each file, or an external tool, you can trick git into staging the rename operation by:

  1. Rename the folder to have a distinctly new name, like "Proto_X"
  2. Stage the parent folder, git add .
  3. Rename the folder to the desired name, including case, like "Proto"
  4. Stage the parent folder again, git add .

This works because the staging operation is where case differences are determined.

mlhDev
  • 2,235
  • 1
  • 22
  • 43