查找所有分支中文件中所有出现的文本 [英] find all occurrences of text in file on all branches

查看:61
本文介绍了查找所有分支中文件中所有出现的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Maven项目中删除了一个依赖项,我想检查是否从所有本地和远程分支中删除了这些行.如何从所有分支返回所有parent/pom.xml文件,并将其grep用作"requestanalyzer"?

I removed a dependency from a Maven project, and I want to check that the lines were removed from all branches, local and remote. How can I return all parent/pom.xml files from all branches, and grep them for "requestanalyzer"?

有一百个远程分支机构.完成此操作后,我不想再留下100个本地分支.

There are a hundred remote branches. After this operation I don't want to be left with 100 local branches.

推荐答案

git for-each-ref 可以为您提供所有本地和远程分支机构的列表:

git for-each-ref can give you the list of all local and remote branches :

git for-each-ref --format="%(refname:lstrip=2)" refs/heads refs/remotes/origin

git grep 可以在任何提交中找到任何模式,并带有文件名过滤器:

git grep can find any pattern in any commit, with filters on file names :

git grep [pattern] [commit] -- [file pattern]

# in your case : look for '<artifactid>requestanalyser' in all pom.xml files :
git grep '<artifactId>requestanalyzer' some/branch -- **/pom.xml


您可以结合使用这两个命令,例如使用bash循环:


You can combine these two commands, using for example a bash loop :

git for-each-ref --format="%(refname:lstrip=2)" refs/heads refs/remotes/origin |\
while read ref; do
    git grep '<artifactId>requestanalyzer' $ref -- **/pom.xml
done

这篇关于查找所有分支中文件中所有出现的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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