【问题标题】:find - folder isn't excluded and sed corrupts git index because of itfind - 文件夹不被排除,sed 会因此而损坏 git index
【发布时间】:2014-02-07 09:29:40
【问题描述】:

我想从find 中排除.git 文件夹,因为sed 总是损坏git 索引文件。我的脚本是:

folder_root="my-files/files"

# change text in files
find $folder_root/ -type f -and -not -path $folder_root/.git -print0 | LC_ALL=en_US.CP437 xargs -0 -n 1 sed -i '' -e 's/fromthis/tothis/g'

git index 仍然被破坏:

error: bad index file sha1 signature
fatal: index file corrupt

【问题讨论】:

    标签: git unix sed find


    【解决方案1】:

    -path "$theme_root/.git" 仅匹配该特定目录,而不匹配该目录中的文件。试试吧

    find "$folder_root/" -name .git -prune -o -type f -print0 | ...
    

    -prune 操作会阻止 find 下降到目录中,因此它会执行您想要的操作并且速度也会更快。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 2012-07-22
      • 2015-06-20
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多