0

I had to search and replace few APIs in a big code base. Therefore, I went for stream editor (sed) rather than using IDE

find . -not -iwholename '*.git*' -print -exec sed -i 's/<old_pattern>/<new_pattern>/g' {} \;

After applying the command git was not able to track (git status, nothing!) my changes anymore. I did exclude '.git' dir but still somehow my local repo was broken. I followed, How to fix corrupted git repository? but I wonder what broke local repo in the first place when '.git' was not touched?

  • You could rerun the command replacing `sed` with `echo sed` to see exactly what commands were run in order to verify that it did what you think it did. – larsks Oct 26 '18 at 12:05
  • 1
    In particular, you didn't exclude what's *in* the `.git` dir, you just didn't run sed on the directory, um, directly. Use `-prune` to tell find not to walk into a directory. – jthill Oct 26 '18 at 12:58
  • For these kind of operations I use this script, which will only consider tracked files by git: https://github.com/Chiel92/replac – chtenb Apr 05 '21 at 09:24

0 Answers0