Searching Git for multiple hash's at one time

201 Views Asked by At

I just got a directive to revert a bunch of committed code. The good news is that all commit's have a reference string in them, something like:

ABC-1556
ABC-1616
ABC-4818
ABC-5919

This commend will give me one of them, how do I modify the grep commend to find them all?

git log --pretty=oneline --abbrev-commit --grep='ABC-1556'
2

There are 2 best solutions below

0
On

I had tried this, but it didn't work:

git log --pretty=oneline --abbrev-commit --grep='ABC-1556|ABC-1616'

But I discovered this did:

git log --pretty=oneline --abbrev-commit --grep=ABC-1556 --grep=ABC-1616

Problem solved!

0
On

You could put all your reference strings into a file (say, patterns), and then use xargs to run the git log command for each string:

xargs -iPATTERN git log --pretty=oneline --abbrev-commit --grep="PATTERN" < patterns

If it's just a small number of patterns you could combine them on the command line like this:

git log --pretty=oneline --abbrev-commit -E --grep="ABC-1556|ABC-1616|ABC-4818|ABC-5919"