I have an entire git repo where I'd like to rename all the files and direcories to lowercase.
Running on Win7, I've added igorecase = false to the gitconfig and renamed a few files through eclipse. The resulting commit now has the two files, one all lowercase and one with upper and lowecase.
Removing the 'undesired' file would dump the version history which is not ideal...
So what is potential method to achieve my goal - thinking only option is batch/shell (not sure how to do recursive directory stuff in there but hopefully someone will be kind ;) )
Any tips recieved with massive thanks and hugs.
The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.
In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.
“Git”, when referring to the system, is a proper noun and is therefore, by English language convention, spelled “Git” with a capital “G”.
When I've had to change case of files in a git repo I just use two renames:
git mv aNiceClass.inc aniceclass.inc_
git mv aniceclass.inc_ aniceclass.inc
Git then happily records the name change:
# Changes to be committed:
#
# renamed: aNiceClass.inc -> aniceclass.inc
Trying to do the rename directly throws this error:
fatal: destination exists, source=aNiceClass.inc, destination=aniceclass.inc
Here's an example shell script which will lowercase the name of any file below the current directory which has an inc
or txt
file extension:
#! /bin/bash
find -E . -regex '.*(inc|txt)$' | while read f
do
lc=$(echo ${f} | tr A-Z a-z)
git mv $f ${lc}_
git mv ${lc}_ $lc
done
That could also be mashed in an ugly little one-liner:
find -E . -regex '.*(inc|txt)$' | while read f; do lc=$(echo ${f} | tr A-Z a-z); git mv $f ${lc}_; git mv ${lc}_ $lc; done
Since the title or tags doesn't mention anything about OS, this works on macOS. It does a git mv
to lowercase on all files in a folder. If you need the force flag just add it in after git mv
.
for f in *; do git mv "$f" "`echo $f | tr "[:upper:]" "[:lower:]"`"; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With