查找所有分支中文件中所有出现的文本 [英] find all occurrences of text in file on all branches
问题描述
我从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屋!