How to output only the "--pretty=" part of git rev-list?

197 Views Asked by At

git rev-list --pretty='%H %an <%ae> %at' origin/topic-branch ^origin/master

outputs the following:

commit d2d0b50ceac50cc81cf991ce09ab3db134af751d
d2d0b50ceac50cc81cf991ce09ab3db134af751d John Doe <[email protected]> 1592392426
commit c5e1438a6ef2e6090c3f9dd9df0a5834b32b50b1
c5e1438a6ef2e6090c3f9dd9df0a5834b32b50b1 John Doe <[email protected]> 1592393061

The desired output should include only the string comprised by the placeholders in the pretty format, like this:

d2d0b50ceac50cc81cf991ce09ab3db134af751d John Doe <[email protected]> 1592392426
c5e1438a6ef2e6090c3f9dd9df0a5834b32b50b1 John Doe <[email protected]> 1592393061

I do not know how to get rid of the default lines printed by rev-list.

1

There are 1 best solutions below

0
phd On BEST ANSWER
git rev-list origin/topic-branch ^origin/master |
    while read sha1; do
        git --no-pager show -s --pretty='%H %an <%ae> %at'
    done

The main part of the trick is git show -s which skips commit headers and only print the pretty part.