Reputation: 6573
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.
Upvotes: 6
Views: 4729
Reputation: 5497
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
Upvotes: 2
Reputation: 1328312
For starter, core.ignorecase
is false by default.
And your commit should have the two files listed, but one for removal, and one for addition.
Upon commit, Git will detect that one has been renamed into the other
(since Git is at its core a content provider).
The history will be preserved (even though you might need a git log --follow -- yourNewFile
in order to get its history)
Note: git 2.0.1 authorizes now a simple git mv a.txt A.txt
: see "Git: Changing capitalization of filenames".
No more need for a script like the one below.
Upvotes: 0
Reputation: 20616
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
Upvotes: 4