Home > Blockchain >  renaming and replacing by string in git repo
renaming and replacing by string in git repo

Time:02-23

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.

Is there a different approach I can use?

CodePudding user response:

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

You can either remove the (D.) quantifier, to avoid globbing "hidden" files (files that start with a period) or add another quantifier, which filters out matches files that starts with git.

Something like this might work:

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

I have added the printf so that you can verify that you list 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.

  • Related