我需要清理我的.gitignore文件。我运行一些命令,然后遍历.gitignore文件并删除不再需要的任何行。
该命令查找树中的所有文件,运行git的check-ignore,仅捕获.gitignore文件中的匹配项,清理行,然后对结果进行唯一排序。没有出现在此输出中的任何规则都可以删除。
find . -type f -not -path .git -exec git check-ignore -v '{}' \; | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$/\1/' | sort -u >> .gitignore
该命令可能要花费一些时间,尤其是在具有很多文件且安装在NFS上的存储库中。
有没有更简单的方法可以向我显示树中任何文件都不匹配的规则?
您可以使用git status --ignored = matching来获取与中的模式匹配的被忽略文件的列表.gitignore
。
git status -s --ignored=matching | grep "^\!\!" | awk '{print $2}' | xargs git check-ignore -v | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$/\1/' | sort -u >> .gitignore
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句