gitgit-branchgit-commitgit-show

Search specific git commit by commit message and exlude branches


I am currently working on a program to filter slow db queries that are stored in a database on the command line.

I would like to search all the commits in all the branches except the one specified and return all the commits that match.

My filter conditions are stored in a database (which is provided for me).

Example:

I have the following entry in the database:

ID key       Query
1  ABCDEF    select * from example
2  0ABCDE    select * from another_example
3  1ABCDE    select * from you_get_the_picture

I am now interested in the queries that haven't been fixed in the code yet. So I need to search through the branches with the key as a search filter.

If the key is found in a commit, skip and look up the next. If no match is found, print it to stdout. All the code works fine but I'm having trouble finding the correct git command.

I have the following:

git grep 'ABCDEF' $(git rev-list ^origin/master) | xargs git show -s --format=%N%s

Which should return all commits containing "ABCDEF" in the commit message in all the branches except origin/master.

However, the git command doesn't return anything which is not possible since I know that these commits are there.

Is my git command not correct? Thanks in advance for any pointers.


Solution

  • This is not what you want:

    $ git rev-list ^origin/master
    $
    

    You asked git rev-list to exclude all revs reachable from origin/master, and to include nothing, so it produces nothing.

    This may be what you meant:

    $ git rev-list --branches ^origin/master
    c2eb39026567499ba9fe0c679766c370462ae26f
    

    Or you might want --tags and/or --remotes as well or instead; or even --all although that includes references like refs/stash.

    Of course, that goes inside the git grep commit arguments as you've shown in your example code; it should work from there—except that git grep produces the matching lines, not commit IDs.