ransh
ransh

Reputation: 1702

Git - remove file extension recursively

I'm trying to remove file extension recursively, but it keeps on failing, whatever I'm trying. Thanks for any idea.

ubuntu@ubuntu-laptop:~/hh/hh_sdk/src/uboot_hh$ git rm -r --cached \*.o
fatal: pathspec 'src/uboot_hh/*.o' did not match any files
ubuntu@ubuntu-laptop:~/hh/hh_sdk/src/uboot_hh$ sudo git rm -r --cached \*.o
fatal: pathspec 'src/uboot_hh/*.o' did not match any files
ubuntu@ubuntu-laptop:~/hh/hh_sdk/src/uboot_hh$ sudo git rm -r --cached *.o
fatal: pathspec 'src/uboot_hh/*.o' did not match any files
ubuntu@ubuntu-laptop:~/hh/hh_sdk/src/uboot_hh$ sudo find . -name *.o -exec git rm -r --cached {} \;
 fatal: pathspec 'src/uboot_hh/lib_arm/_divsi3.o' did not match any files
fatal: pathspec 'src/uboot_hh/lib_arm/cache.o' did not match any files
fatal: pathspec 'src/uboot_hh/lib_arm/_udivsi3.o' did not match any files
fatal: pathspec 'src/uboot_hh/lib_arm/_umodsi3.o' did not match any files

Upvotes: 2

Views: 1449

Answers (2)

Khanakia
Khanakia

Reputation: 742

It seems your files are already ignored that's why git gives the error when you execute the command

find -name '*.log' -type f -exec git rm --cached {} \;

### fatal: pathspec './modules/logger/logs/newleaf_2019-08-19.log' did not match any files

So please first check is your file is ignored already or not you can run this command to test the files if ignored already or not

find -name '*.log' -exec git check-ignore --v {} \;

OR TEST SINGLE FILE

git check-ignore --v ./modules/logger/logs/test.log

if Files ignore you get will get this output otherwise, it will returns empty.

.gitignore:4:logs/      ./modules/logger/logs/test.log

Upvotes: 0

hek2mgl
hek2mgl

Reputation: 157947

The find approach should work well but you need to single-quote the '*.o' pattern since the shell would otherwise expand the * before passing it to find.

Also you need to pass the --force option (-f) to git rm if the file does not exists in the file system anymore:

find -name '*.o' -exec git rm -f -r --cached {} \;

Upvotes: 3

Related Questions