Git : Rename file with difference in casing

In this blog post, I will explain on how to properly rename a file with difference in casing using git mv command. Before that first let us understand, why difference in casing is such a big thing when it comes to version control systems.

SetUp

  • Create a new git repository
  • Create a new file called OriginalText.txt and add it to the repository
  • Commit the change and push the change to the main repository

In my local, I have created a new repo in github : https://github.com/pawanmishra/playground, cloned it in local and followed the steps mentioned above. With initial commit, the repo looks like this:

image

 

Attempt 1 : Rename file to originafile.txt using git mv command. Try issuing the following command :  git mv OriginalFile.txt originalfile.txt

The above command fails with following error : fatal: destination exists, source=OriginalFile.txt, destination=originalfile.txt.

The issue here is that git is unable to rename file because its thinking the source & target file are same.

Attempt 2 : Rename file using windows explorer(F2). Select file, press F2 and rename it to originalfile.txt. This works but unfortunately if you issue git status command in the repo then git returns nothings. Git is still unable to recognize that the file has been renamed.

Attempt 3 : Using git mv command. We can rename a file with difference in casing using a two step process. In the first step use “git mv” command to rename file to some temporary file name and then in second step rename temporary file into the expected file name. For e.g. If I have to rename OriginalFile.txt to originalfile.txt, then the steps would be :

git mv OriginalFile.txt tmpFile.txt
git mv tmpFile.txt originalfile.txt

Attempt 4 : Simplest of all, use git mv command with –f flag(force) override. The above mentioned two step process can be simplified using the following command :

git mv -f OriginalFile.txt originalfile.txt

Its important to remember that, Windows & OS X are case-insensitive operating systems whereas Linux is case-sensitive operating system. Thus its possible that if a file not renamed(with difference in casing) properly, then that it might be listed only oncein Windows OS but if you commit it and push it to the git main repo, over there it will appear as two different files.

For more please see the following StackOverflow thread : http://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git

Thanks.

Contact Me

rk.pawan@gmail.com | +1-737-202-7676 | LinkedIn | Facebook | Github |

No Comments

Add a Comment

As it will appear on the website

Not displayed

Your website