Git

How do I Commit Case-sensitive Only Filename Changes in Git?

While working on Git, sometimes, developers may need to change file names for different reasons, such as if they notice a spelling mistake or for clarity. However, Git is case-sensitive when it comes to filenames. So, if the user renames a file to have a different case than it previously had, Git will see it as a separate file, and you may need to rename the file and commit changes.

This article will explain the procedure to commit case-sensitive filename changes/modifications in Git.

How to Commit Case-sensitive Only Filename Changes/Modifications in Git?

To commit case-sensitive only filename modifications in Git, try out the following instructions:

  • Switch to a particular repository.
  • Change the case sensitivity to “false” using the “git config core.ignorecase false” command.
  • Generate a new file and add it to the Git Index.
  • Rename the file to the correct case using the “git mv <old-file-name> <new-file-name>” command.
  • Track and commit new changes.
  • Verify changes

Step 1: Move to Local Repository

First, write out the given-provided command and switch to the local repository:

$ cd "C:\Git\Repos1

Step 2: Check Ignore Case Value

Next, check the default case sensitivity by executing the following command:

$ git config core.ignorecase

It can be seen that the case sensitivity option is “false”, which ensures that Git will only commit changes to filenames that are case sensitive:

Step 3: Create a New File

Now, type out the “touch” command to make a new file:

$ touch demofile.txt

Step 4: Track File

Add the file to the Git staging area using the below-listed command:

$ git add demofile.txt

Now, suppose that the user wants to change the case of the file and then commit changes. To do this, follow the next instructions.

Step 5: Rename File to Correct Case

Run the “git mv” command along with the old file name and specify the new file name to rename it according to the correct case:

$ git mv demofile.txt Demo_File.txt

Step 6: Add New Changes to Git Index

Then, track new changes using the “git add” command and specify a new file name:

$ git add Demo_File.txt

Step 7: Commit Changes

Next, commit changes along with the desired commit message using the “git commit” command:

$ git commit -a -m "Commenting case-sensitive only filenames changes"

Here, the “-a” option is used to automatically stage and commit changes to files that are already tracked by Git, and the “-m” option is utilized to specify the commit message.

The below output indicates that the changes have been committed and the filename has been renamed successfully:

Step 8: Verify Changes

Lastly, ensure that the changes have been committed by checking the Git log:

$ git log

As you can see, the new changes have been committed:

We have provided the easiest way to commit case-sensitive only filename changes in Git.

Conclusion

To commit case-sensitive only filename changes in Git, first, navigate to a particular repository. Then, change the case sensitivity to “false” using the “git config core.ignorecase false” command. After that, make a new file and track it. Next, rename the file to the correct case, track and commit new changes. This article explained the procedure to commit case-sensitive filename changes/modifications in Git.

About the author

Laiba Younas

I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.