有没有一种简单的方法来显示目录树中任何文件都不匹配的 .gitignore 规则?
Is there a simple way to show .gitignore rules that are not matched by any file in the directory tree?
我需要清理我的 .gitignore 文件。我 运行 一些命令,然后通过 .git 忽略文件并删除不再需要的任何行。
该命令找到树中的所有文件,运行s git 的检查忽略,仅 gres 出我的 .git 忽略文件中的匹配项,清理行,然后对结果进行唯一排序。任何未出现在此输出中的规则都可能被删除。
find . -type f -not -path .git -exec git check-ignore -v '{}' \; | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$//' | sort -u >> .gitignore
此命令可能需要相当长的时间,尤其是在包含大量文件并挂载在 NFS 上的存储库中。
有没有更简单的方法可以显示与树中任何文件都不匹配的规则?
您可以使用 git status --ignored=matching 获取与 .gitignore
中的模式匹配的被忽略文件的列表。
git status -s --ignored=matching | grep "^\!\!" | awk '{print }' | xargs git check-ignore -v | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$//' | sort -u >> .gitignore
我需要清理我的 .gitignore 文件。我 运行 一些命令,然后通过 .git 忽略文件并删除不再需要的任何行。
该命令找到树中的所有文件,运行s git 的检查忽略,仅 gres 出我的 .git 忽略文件中的匹配项,清理行,然后对结果进行唯一排序。任何未出现在此输出中的规则都可能被删除。
find . -type f -not -path .git -exec git check-ignore -v '{}' \; | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$//' | sort -u >> .gitignore
此命令可能需要相当长的时间,尤其是在包含大量文件并挂载在 NFS 上的存储库中。
有没有更简单的方法可以显示与树中任何文件都不匹配的规则?
您可以使用 git status --ignored=matching 获取与 .gitignore
中的模式匹配的被忽略文件的列表。
git status -s --ignored=matching | grep "^\!\!" | awk '{print }' | xargs git check-ignore -v | grep '^.gitignore:' | sed 's/.*:\(.*\)\t.*$//' | sort -u >> .gitignore