gpt4 book ai didi

git - grep 用于多个 git 存储库中的内容

转载 作者:太空狗 更新时间:2023-10-29 13:18:15 26 4
gpt4 key购买 nike

所以我从其他一些开发人员那里继承了一个相当大的代码库,代码存储在各种 git 存储库中。

有时,很难知道一段特定的代码可能位于哪个项目中,或者那段代码是否存在于 git 中。

我想要做的是 grep 一些特定文本的所有项目。

我正在使用 gitosis,因此所有 git 存储库都存储在/home/git/repositories 中,其结构如下:

/home/git/repositories
|- project1
|- HEAD
|- branches
|- config
|- description
|- hooks
|- info
|- objects
|- refs
|- project2
|- ...

我试过像这样对对象目录中的内容进行递归 grep:

grep -Hr "text" /home/git/repositories/*/objects

这当然无法按我的预期工作,因为对象是以 git 的自定义格式存储的。

做什么?

最佳答案

git grep 与 ref 或 --no-index 一起使用:

cd /home/git/repositories
for i in *; do ( cd $i; git grep text HEAD ); done

关于git - grep 用于多个 git 存储库中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11543593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com