Sun, 10 Jun 2018 12:16:22 +0000

最近想写一些自己的项目,然后在公司锁包 yarn.lock,发现其 resolved 是内网的 npm,考虑到我还不太想把内网的域名发到 GitHub 上,那我就来批量修改一下吧。

首先直接动手用 git filter-branch --tree-filter "sed -i '' 's/first/second/g' filename",然后报错 sed: filename: No such file or directory。这时候想到 commit 从头往后找,前面几个 commit 肯定没有这个文件。因为这个文件是最近几个 commit 才有的。然后想需要配合 find 来做这个操作。

find ./foldName -name 'xxx' 发现 find 也同样面临这个问题,find: ./foldName: No such file or directory。这样的话只能是找到所有文件然后过滤掉,过滤用 grep,即 find . -name 'yarn.lock' | grep -v 'node_modules'

整理可得:

$ git filter-branch -f --tree-filter "find . -name 'yarn.lock' | grep -v 'node_modules\|otherFolder' | xargs sed -i '' 's/first/second/g' filename""


blog comments powered by Disqus