Search code examples
gitformatgit-log

Git Log Pretty Format - Grab just a number from the title


When we merge code all titles have a pull request number (#500)

Using git log I can grab the title:

git log --after=2017-04 --pretty=format:"%s"

Which would give me a string like this:

Adding 5 new features (#500)

How do I extract only the number contained in (#).

Input:

git log --after=2017-04 --pretty=format:"foo"

Output:

500


Solution

  • Awesome, seems like easiest way if to just use the output and pipe to a tool and use regex. Thanks @Flimzy

    I ended up doing this:

    echo "Adding 5 new features (#500)" | grep -o '#[0-9]\+' | grep -o '[0-9]\+'