11

そのため、他の開発者からかなり大きなコードベースを継承し、コードはさまざまなgitリポジトリに格納されています。

特定のコードがどのプロジェクトにあるのか、またはそのコードがgitに存在するのかどうかを判断するのが難しい場合があります。

私がやりたいのは、特定のテキストのすべてのプロジェクトをgrepすることです。

私はgitosisを使用しているので、すべてのgitリポジトリは次のような構造で/ home / git/repositoriesに保存されます。

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

私は次のようにobjectsディレクトリにあるものに対して再帰的なgrepを実行しようとしました:

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

もちろん、オブジェクトはgitのカスタム形式で保存されているため、これは意図したとおりに機能しません。

何をしますか?

4

3 に答える 3

9

git grepref または で使用し--no-indexます。

cd /home/git/repositories
for i in *; do ( cd $i; git grep text HEAD ); done
于 2012-07-18T14:28:39.167 に答える
4

古い質問は知っていますが、コマンドラインを使用する場合は、これをbash_profileまたはに追加できますbashrc

ggrep() {
    find . -type d -name .git | while read line; do
        (
        cd $line/..
        cwd=$(pwd)
        echo "$(tput setaf 2)$cwd$(tput sgr0)"
        git grep -n "$@"
        )
    done
}

上記の機能の基本的な要点は、.git最初にそのディレクトリを含むすべてのディレクトリを検索し、次にそのトークンが発生する行番号とともにファイルを出力することです

次に、に移動し/home/git/repositoriesて検索します

ggrep "InvalidToken"

このように出力されます

/home/git/org/repo1
/home/git/org/repo2
/home/git/org/repo3
/home/git/org/repo3
lib/v3/Utility.pm:59:         code              => 'InvalidToken',
lib/v3/Utility.pm:142:        code              => "InvalidToken",

次のようなフラグを渡すこともできますggrep -i "search"(大文字と小文字を区別しない検索用)

于 2016-03-26T19:46:46.720 に答える
2

マルチを使用します。git grep一度に複数のリポジトリを介して特別に作成されました。

$ ls
vim spring-framework gradle phantomjs
$ multi -i "fantastic"
vim
====================================================
runtime/doc/quotes.txt:VIM 4.5 is really a fantastic editor.  It has sooooo many features and more
runtime/doc/quotes.txt:fantastic it is! (Tony Nugent, Australia)
spring-framework
====================================================
gradle
====================================================
subprojects/docs/src/docs/userguide/ant.xml:        simply by relying on Groovy, and the fantastic <literal>AntBuilder</literal>.
subprojects/docs/src/docs/userguide/buildScriptsTutorial.xml:            relying on Groovy. Groovy is shipped with the fantastic <literal>AntBuilder</literal>. Using Ant tasks
subprojects/docs/src/docs/userguide/ideSupport.xml:            if you do this you have a fantastic IDE support for developing Gradle scripts. Of course if you use
phantomjs
====================================================
test/ghostdriver-test/fixtures/common/macbeth.html:<A NAME=1.3.55>Are ye fantastical, or that indeed</A><br>
test/ghostdriver-test/fixtures/common/macbeth.html:<A NAME=1.3.148>My thought, whose murder yet is but fantastical,</A><br>
于 2015-09-03T16:56:46.640 に答える