Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

renaming and replacing by string in git repo

I am working on a project named XXX.
I want to replace every instance of XXX to YYY. (I wish to replace the string inside all files and also rename files/directories that contain the string XXX to YYY).

What I have done and where I’m stuck:

git checkout -b renameFix

// in zsh

sed -i -- 's/XXX/YYY/g' **/*(D.) // replace

zmv '(**/)(*XXX*)' '$1${2//XXX/YYY}'  // rename files and dirs

Now, when I run git status, I get "fatal: unknown index entry format 0x2f700000" error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a different approach I can use?

>Solution :

Your problem is that your glob (**/*(D.)) traverses the .git directory.

You can add either remove the (D.) quantifier, to avoid globbing "hidden" files (files that start with a period) or add another quantifier, something like:

ignore_git() { ! [[ $REPLY =~ "^.git" ]] }
printf '%s\n' **/*(D.+ignore_git)

I have added the printf so that you can verify that you globs the files that you want.

You can also take a look at git ls-files which can produce a list of files that git tracks.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading