40

I want to rename a directory versioned by Git on a Windows system (change the case of the directory name):

$ git mv docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied

I've also tried with the force-option - but with the same result:

$ git mv --force docs DOCS
Rename from 'docs' to 'DOCS/docs' failed. Should I try again? (y/n) n
fatal: renaming 'docs' failed: Permission denied

For some reason Git fails because it thinks DOCS already is an existing directory and the directory should be moved inside it. I know that I can rename & commit using a temporary directory name and then rename & amend-commit to the final name, but isn't there a way to tell Git that I don't want to move inside any other directory?

T0xicCode
  • 4,583
  • 2
  • 37
  • 50
Thomas S.
  • 5,804
  • 5
  • 37
  • 72
  • Does this answer your question? [I change the capitalization of a directory and Git doesn't seem to pick up on it](https://stackoverflow.com/questions/6899582/i-change-the-capitalization-of-a-directory-and-git-doesnt-seem-to-pick-up-on-it) – samm May 27 '22 at 06:03

4 Answers4

68

You can try to do it in 2 step.

$ git mv docs DOCS2
$ git mv DOCS2 DOCS

it will work

  • 4
    Why can't git do this internally? – Thomas S. Apr 22 '16 at 18:29
  • 1
    Git was originally done to work on Linux based system, which is case-sensitive. Windows is not. It is not possible, in windows, to have 2 folders with the name "ABC" and "abc" at the same place. The issue is not with git per say, the same behavior happens with SVN or any other application under windows that doesn't explicitly take care of that problem. The issue is with the OS. – Pierre-Luc Dupont Apr 27 '16 at 12:47
  • 2
    The issue is not with the OS, because Windows can rename a directory from docs to DOCS or Docs. It is a problem of the tool which does not support case-insensitive, case-preserving file systems. – Thomas S. Apr 27 '16 at 14:35
  • I mean that the OS is reacting differently when checking if the destination file already exists. – Pierre-Luc Dupont May 02 '16 at 13:38
  • I mean that the OS is reacting differently when checking if the destination file already exists. For example, with this Java Test file. `public class Test { public static void main(String args[]) { System.out.println(new java.io.File("a.txt").exists()); System.out.println(new java.io.File("A.txt").exists()); } }` When there is a file name A.txt, in Linux, the result will be `false true ` in windows, it will be `true true ` It is not the OS per say the problem. But if the program is looking for a file in linux, it is case sensitive, not in windows. – Pierre-Luc Dupont May 02 '16 at 13:44
  • Also, in linux, it is possible to have A.txt and a.txt in the same folder. Not in windows, you get a File exists error. – Pierre-Luc Dupont May 02 '16 at 13:45
  • 1
    It depends on the file system, not the OS. On Linux or OS X you also may have the problem with case-insensitive/case-preserving file systems. – Thomas S. May 02 '16 at 16:50
  • 2
    Imho you could argue that git already has to do things differently on Windows. I agree that there is a problem for git to detect the change when you rename the file in Windows, but if you use `git mv` it should work. I think it's more likely the devs simply have no interest in implementing a special case for this. It's more like "we're coming from Linux, and that's just the way it works". – Oliver Schimmer Nov 21 '18 at 11:57
  • worked pretty well on OSX too, thanks! – SkyzohKey Sep 03 '22 at 11:34
  • @Pierre-LucDupont hold my beer... https://learn.microsoft.com/en-us/windows/wsl/case-sensitivity – Robert Koritnik Dec 01 '22 at 07:39
0

I have tried to rename my directory with TortoiseGit using rename, command prompt using git mv, and git bash using git mv. The move command was either mv Status status or git mv Status status2 and both of them respond "failed: Permission denied". So it seems I am either going to have to delete the git repository and create a new one with the new directory name structure or I am going to have to create a Linux VM, clone it down, and try to rename name it there. It seems only files can be renamed under windows, but directories just fail. As for people that say git mv works for them, there has to be something missing in your setup.

-1

Since windows iד case sensitive you cant rename the file to the same letters. (Docs == docs [ignored case])

You can do it from git bash since git bash is cygwin and its case sensitive since its a unix emulator.

The command is git mv

git mv <old name> <new name>

Here is a demo from git bash. (windows 7) enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 1
    Please try again with directories. – Thomas S. Apr 23 '16 at 05:07
  • With Windows 10 using the graphical interface, if a file, or directory, is renamed case only, the displayed name is in the original case. If the file, or directory is clicked on again the new case is displayed in the edit box, but it will again return to the original case. So it appears that the case hasn't changed when it might have. This can be show by opening a Command Prompt and using the dir command. The case shown doesn't always agree with that shown in the Explorer window. – Quentin 2 Jul 12 '18 at 10:33
-2

No. There isn't a way to tell Git that you don't want to move the folder inside any other directory.

This is not a limitation of git, but rather a limitation of Windows and NTFS. Because the filesystem is case-insensitive, it reports that the case-changed new name already exists, which causes the behaviour that you encounter. Try a 2 step rename (with a temporary name), then commit, or changing it on a non-windows (technically on a case-sensitive filesytem) computer.

T0xicCode
  • 4,583
  • 2
  • 37
  • 50
  • 4
    Your first sentence can't be right, because in the Windows Explorer I can rename a directory only by case without any problems. – Thomas S. Apr 22 '16 at 18:28