ITSUUUUUH ITSUUUUUH - 1 month ago 5x
Git Question

How to count multiple lines from git log in PowerShell?


git log --pretty=oneline $branch...$version

Allows me to determine how many commits are between the specified branch and tag. Each commit is printed to the console window on a different line, and starts with 40 characters of that commit's SHA and is followed by a brief description.

Using PowerShell, I would like to take the count of all these commits and assign it to a variable. I don't want to output this data to a file.

My assumption is that a large regex would be the best option, but I'm thinking that there must be an easier solution.


Is there an easier way to find the count of multiple lines outputted to the console?

Also, is there a way to get around the buffer size when handling the log data without adjusting the buffer-size of the console window? Or is this a factor I will need to worry about at all? (when handling a large amount of commits)


This should do what you need:

(git log --oneline $branch...$version | Measure-Object -Line).Lines

This will give you the raw number, which you can assign to a variable. You won't need to worry about pagination with a large number of commits; Git disables pagination when the output is being piped.