如何grep搜索尚未上演(索引)的工作目录的修改文件? [英] How to grep search in modified files of working directory which are not yet been staged(indexed)?

查看:143
本文介绍了如何grep搜索尚未上演(索引)的工作目录的修改文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 git grep 没有任何选项可在索引这些文件之前仅在工作目录修改的文件中进行搜索。是否有任何原生git命令为此目的,或者我应该使用组合git / linux命令?

It seems git grep doesn't have any option to search only in working directory modified files prior to indexing those files. is there any native git command for this purpose or should I use a combo git/linux commands?

推荐答案

通过使用linux grep git ls-files

by using linux grep and git ls-files:

$ grep -s "search pattern" $(git ls-files -m)

注1:为提供了grep的 -s 选项,用于抑制关于不存在或不可读文件的错误消息 git ls-files -m 列出了删除的文件,导致 grep 给出遇到不存在的文件时,没有这样的文件或目录错误。

note 1: grep's -s option is provided for Suppress error messages about nonexistent or unreadable files because git ls-files -m lists deleted files too which causes grep give "No such file or directory" error when encounters a nonexistent file.

注意2:git ls-files' - m 选项仅用于列出修改文件(其中也列出了已删除的文件!)

note 2: git ls-files' -m option is for listing only modified files(which also lists removed files too!)

这篇关于如何grep搜索尚未上演(索引)的工作目录的修改文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆