0

PROBLEM

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.

QUESTION
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)

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Scott's version works fine, but you could also do it like this:

(git log --oneline $branch...$version).length

if you need to filter the output, use select-string with a regex, e.g:

(git log ... | select-string "^commit ").length

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.