1

I got 100 of images which I needed to rename from .JPG to .jpg. I already wrote a gulp task and renamed them all. Now Git is not recognizing the change.

I found this on single files: I change the capitalization of a directory and Git doesn't seem to pick up on it

But I don't want to do this on each image by hand is it possible to use s.th. like this

git mv **/*/.JPG **/*.temp

git mv **/*/.temp **/*.jpg

The images are all in diff. folders! E.g. src/a, src/a/b src/b ...

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68

3 Answers3

1
for line in $(find -type f -name '*.JPG'
               | sed 's@\(.*\)\.JPG@\1.JPG \1.jpg/')
do
    git mv $line
done

If you already renamed your files you just need to git add them. Since they haven't changed git will notice they all have the the same blob object and setup the renaming. If you don't have any other unknown or changed files in your git working dir, one possible way is:

for path in $(git status --porcelain | sed 's/.. //')
do
    git add "$l"
done
jvdm
  • 846
  • 6
  • 22
  • I already renamed them. So I guess I have to use the second solution. Can you explain a bit more to the solution. I'm always afraid when doing crazy moves on my git repo. – Andi Giga Jul 10 '15 at 19:51
  • You don't need to be afraid, as long as you have a clone somewhere with your previous repo status. – jvdm Jul 10 '15 at 20:27
  • Regarding the operation, you're just telling git that some files should be marked for deletion and addition: git is smart enough to known they are indeed the same file and then mark them as a "file movement" (renaming). – jvdm Jul 10 '15 at 20:33
  • Ok thanks I just copied that into my console. When I do the first solution (I took the unchanged images) it gives me `$line: not a valid identifier` – Andi Giga Jul 10 '15 at 22:31
1

There is a small change to the answer given by @jvdm to make the first code snippet work.

for line in $(find -type f -name '*.JPG'
              | sed 's@\(.*\)\.JPG@\1.JPG \1.jpg/')
do
    git mv $line
done
vchethan
  • 113
  • 1
  • 8
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Biswajit_86 Jul 12 '15 at 01:05
  • Ok... got it.. Thanks for letting me know. – vchethan Jul 12 '15 at 01:09
  • Unfortunately this does not work either: `find: illegal option -- t usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression] find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] -bash: command substitution: line 2: syntax error near unexpected token \`|' -bash: command substitution: line 2: \` | sed 's@\(.*\)\.JPG@\1.JPG \1.jpg/'' ` – Andi Giga Jul 13 '15 at 12:58
1

This works:

for file in $(git ls-files '*.JPG'); 
do git mv -f $file $(echo $file |sed 's/\.JPG/\.jpg/'); done
  • git ls-files lists all files => '*.JPG' filters
  • git mv -f moves the files (-f = force, which is required)
  • $file returns the original filename
  • $(echo $file |sed 's/\.JPG/\.jpg/')is the new filename

Helpful threads:

git rename many files and folders

How to rename large number of files

Community
  • 1
  • 1
Andi Giga
  • 3,744
  • 9
  • 38
  • 68
  • The shell will do simple string work, `mv -f "$file" "${file%.JPG}.jpg"` instead of your `echo`+`sed`. – jthill Jul 13 '15 at 15:24